Skip to content

feat(offline_first): set policy for associations #569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

TillJohanndeiter
Copy link

fixes #568

Add an option to set the OfflineFirstGetPolicy for associations. As described before i experienced performance issues if i use alwaysHydrate with Model that have (nested) associations. So i added here an optional parameter to specify the policy for associations.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Great news! Jit hasn't found any security issues in your PR. Good Job! 🏆

Copy link
Collaborator

@tshedor tshedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TillJohanndeiter Thank you for opening this PR. Could you please add tests for this too to the brick_offline_first package?

@tshedor tshedor changed the title Set policy for associations feat(offline_first): set policy for associations Apr 9, 2025
Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ The following Jit checks failed to run:

  • secret-detection

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ The following Jit checks failed to run:

  • secret-detection

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

Copy link

@jit-ci jit-ci bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ The following Jit checks failed to run:

  • secret-detection

#jit_bypass_commit in this PR to bypass, Jit Admin privileges required.

More info in the Jit platform.

get<TModel>(
query: query,
policy: policy,
associationPolicy: associationPolicy,).then(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it's missing a formatting check

@@ -7,12 +7,17 @@ Future<Horse> _$HorseFromTest(
}) async {
return Horse(
name: data['name'] as String?,
mounties: await Future.wait<Mounty>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this removed?

this.name,
this.mounties = const <Mounty>[],
});
final Owner? owner;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of adding another model, why can't the existing Mounty be used?

@@ -291,7 +295,7 @@ abstract class OfflineFirstWithSupabaseRepository<
case PostgresChangeEvent.all:
final localResults = await sqliteProvider.get<TModel>(repository: this);
final remoteResults =
await get<TModel>(query: query, policy: OfflineFirstGetPolicy.awaitRemote);
await get<TModel>(query: query, policy: OfflineFirstGetPolicy.awaitRemote, associationPolicy: associationPolicy);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both OfflineFirstWithRestRepository and OfflineFirstWithGraphqlRepository need to be updated

@@ -176,7 +176,9 @@ abstract class OfflineFirstRepository<TRepositoryModel extends OfflineFirstModel
/// is ignorable (e.g. eager loading). Defaults to `false`.
@override
Future<List<TModel>> get<TModel extends TRepositoryModel>({
OfflineFirstGetPolicy policy = OfflineFirstGetPolicy.awaitRemoteWhenNoneExist,
OfflineFirstGetPolicy? associationPolicy,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new parameter requires doc comments on this get method

@@ -244,6 +246,7 @@ abstract class OfflineFirstRepository<TRepositoryModel extends OfflineFirstModel
/// can be expensive for large datasets, making deserialization a significant hit when the result
/// is ignorable (e.g. eager loading). Defaults to `false`.
Future<List<TModel>> getBatched<TModel extends TRepositoryModel>({
OfflineFirstGetPolicy? associationPolicy,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here - this will need documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

OfflineFirstGetPolicy alwaysHydrate is unexpectedly slow
2 participants