-
Notifications
You must be signed in to change notification settings - Fork 200
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
feat(datastore): selective sync on initial sync & incoming subscription models #884
Conversation
Codecov Report
@@ Coverage Diff @@
## main #884 +/- ##
==========================================
+ Coverage 66.00% 66.09% +0.09%
==========================================
Files 874 875 +1
Lines 34608 34769 +161
==========================================
+ Hits 22843 22982 +139
- Misses 11765 11787 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/DataStoreSyncExpression.swift
Outdated
Show resolved
Hide resolved
b4996df
to
8ebb9aa
Compare
8ebb9aa
to
6d5c795
Compare
self.errorHandler = errorHandler | ||
self.conflictHandler = conflictHandler | ||
self.syncInterval = syncInterval | ||
self.syncMaxRecords = syncMaxRecords | ||
self.syncPageSize = syncPageSize | ||
self.syncExpressions = syncExpressions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@palpatim mentioned to combine a lot of these sync config parameters, but doing it this way seems to align better with android:
https://github.com/aws-amplify/amplify-android/blob/baa798bda6c97e9c8415792c4efcdc9dffb7ee3d/aws-datastore/src/main/java/com/amplifyframework/datastore/DataStoreConfiguration.java#L60
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as our ultimate behavior is the same, I'm not too interested in hewing closely to Android platform conventions. Even with named arguments and defaults, a pattern like:
let foo = DataStoreConfiguration(
errorHandler: self.handleDataStoreError,
conflictHandler: self.handleDataStoreConflict,
syncInterval: 86_400,
syncMaxRecords: 10_000,
syncPageSize: 100,
syncExpressions: [(Post.foo == getLatestValue()), (Post.bar < getSomeOtherValue()) ]
)
is pretty unwieldy. Even if we provide defaults, the named arguments must be provided in the same order, which adds friction to the customer's implementation.
Consider encapsulating the initializer arguments in purpose-built types (we have pluginOptions
on our config types), or adopting a different construction pattern (Builder, for example) to let the customer have an easier time of initializing these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regrading the configuraiton object being unwieldy, that is the worst case scenario. For customers only wanting to specify a selective sync, it would look something like this:
let syncExpression1 = DataStoreSyncExpression.syncExpression(Todo.schema, where: {
Todo.keys.tag == AppDelegate.tagToSearch
})
let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels(),
configuration: .custom(syncExpressions: [syncExpression1]))
Are you still concerned about bloating this interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error handler and conflict handler seem like reasonable things to specify as well, but I'm guessing we don't have any data on how many customers are using which of the config options. It seems to me that 4 free-floating and yet sync-related arguments is excessive, but it's ultimately a judgement call, so consider this as my vote against it. I'm willing to be outvoted. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overall design makes sense, but I'm not joyful about the growth of the DataStoreConfiguration interface, and I don't like passing that whole configuration object around to the underlying components. Comments inline
self.errorHandler = errorHandler | ||
self.conflictHandler = conflictHandler | ||
self.syncInterval = syncInterval | ||
self.syncMaxRecords = syncMaxRecords | ||
self.syncPageSize = syncPageSize | ||
self.syncExpressions = syncExpressions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as our ultimate behavior is the same, I'm not too interested in hewing closely to Android platform conventions. Even with named arguments and defaults, a pattern like:
let foo = DataStoreConfiguration(
errorHandler: self.handleDataStoreError,
conflictHandler: self.handleDataStoreConflict,
syncInterval: 86_400,
syncMaxRecords: 10_000,
syncPageSize: 100,
syncExpressions: [(Post.foo == getLatestValue()), (Post.bar < getSomeOtherValue()) ]
)
is pretty unwieldy. Even if we provide defaults, the named arguments must be provided in the same order, which adds friction to the customer's implementation.
Consider encapsulating the initializer arguments in purpose-built types (we have pluginOptions
on our config types), or adopting a different construction pattern (Builder, for example) to let the customer have an easier time of initializing these.
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/DataStoreSyncExpression.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Sync/InitialSync/InitialSyncOperation.swift
Outdated
Show resolved
Hide resolved
...e/AWSDataStoreCategoryPlugin/Sync/SubscriptionSync/AWSIncomingEventReconciliationQueue.swift
Outdated
Show resolved
Hide resolved
...AWSDataStoreCategoryPlugin/Sync/SubscriptionSync/AWSIncomingSubscriptionEventPublisher.swift
Outdated
Show resolved
Hide resolved
...SDataStoreCategoryPlugin/Sync/SubscriptionSync/IncomingAsyncSubscriptionEventPublisher.swift
Outdated
Show resolved
Hide resolved
...DataStoreCategoryPluginTests/Sync/SubscriptionSync/Support/MockModelReconciliatinQueue.swift
Outdated
Show resolved
Hide resolved
...SDataStoreCategoryPlugin/Sync/SubscriptionSync/IncomingAsyncSubscriptionEventPublisher.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/DataStoreConfiguration.swift
Show resolved
Hide resolved
…yncExpression.swift Co-authored-by: Tim Schmelter <[email protected]>
…alSync/InitialSyncOperation.swift Co-authored-by: Tim Schmelter <[email protected]>
Smoke tested with a basic case.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.