amplify-flutter
amplify-flutter copied to clipboard
Amplify how to stop auto sync feature for Specific models
I am using 2 Configurations for amplify
// To save data in offline without starting sync
void configureOffline() async {
Amplify.addPlugin(AmplifyDataStore(
modelProvider: ModelProvider.instance,
));
await Amplify.configure(amplifyconfig);
}
// to sync offline data or new data in server
void configureAmplifyOnline() async {
await Future.wait([
Amplify.addPlugin(AmplifyDataStore(
modelProvider: ModelProvider.instance,
syncExpressions: [
// DataStoreSyncExpression(AllRetailerList.classType,
// () => AllRetailerList.SALES_LIST.contains("3")),
DataStoreSyncExpression(
ProductData.classType, () => ProductData.STATUS.eq(1)),
])),
Amplify.addPlugin(AmplifyAPI()),
]);
await Amplify.configure(amplifyconfig);
}
i want to sync data from ProductData only and not to from SALES_LIST but configureAmplifyOnline() sync all data how to stop auto sync for specific MODELS?
Hi @sagar14791 thanks for asking! Currently there is no way to configure a specific model to be excluded from the sync engine programmatically.
Is SALES_LIST a model? Or a filed of a model?
SALES_LIST
it is a field of type list in the "AllRetailerList" model
Hi @sagar14791 thanks for asking! Currently there is no way to configure a specific model to be excluded from the sync engine programmatically.
Is
SALES_LISTa model? Or a filed of a model?
my requirement is that I have 5 models which I want to sync when the application starts for the first time on a particular date it will sync all data from the server after that I have the condition, that if the date is the same it will not sync for that day again. after that, I add data in the new 6th model which I use to add data in offline mode, once all is done user can click on the button to sync data from the 6th model to the server without disturbing other models.
Hey @sagar14791 sorry for the super delayed response, I completely lost track of this issue...
that if the date is the same it will not sync for that day again.
Have you tried to specify syncInterval when initiating DataStore? It should be to achieve what you are looking for.
after that, I add data in the new 6th model which I use to add data in offline mode, once all is done user can click on the button to sync data from the 6th model to the server without disturbing other models.
I need a bit clarification on this:
- 5/6 models you mean 5/6 records of the same model? Or they are records of different models
- can you explain "without disturbing other models." do you mean sync only the 6th record, and not syncing others?
Hi @HuiSF everything is model class not records in model 5/6 models means 5 models will get data from Amplify database once i start application and in 6th model i will be saving data locally using datastore query eg. await Amplify.Datastore.save(data); what i want to achieve is if 5 models are already synced then i don't want to sync data inside them again but my 6th model has some data locally which i want to send to server then server will update few fields in amplify and then i want updated data again for 6th model only not for other model
@HuiSF also will there be any feature coming soon for Amplify Re-Configuration?
Hi @HuiSF everything is model class not records in model 5/6 models means 5 models will get data from Amplify database once i start application and in 6th model i will be saving data locally using datastore query eg. await Amplify.Datastore.save(data); what i want to achieve is if 5 models are already synced then i don't want to sync data inside them again but my 6th model has some data locally which i want to send to server then server will update few fields in amplify and then i want updated data again for 6th model only not for other model
Sorry for the delayed response @sagar14791 I think what you are asking has already been supported today in DataStore.
- DataStore performs full sync (sync all syncable data from AppSync) on each fresh start (newly installed App e.g.)
- After full sync, DataStore performs delta sync on each App start (sync only changed data) with in the specified
syncInterval, if you don't want frequent full sync, you can set a relatively largersyncIntervalaccording to your use case. - when a new record is added to local DataStore, only the newly added record will be synced to cloud via AppSync mutation (assuming you haven't changed other records in your local store)
- When changes are made to other records in cloud, the new changes will be synced into your device
- When you cold start the App the new changes are synced via delta sync or full sync
- When the App is running, the new changes are synced via AppSync subscription
@HuiSF also will there be any feature coming soon for Amplify Re-Configuration?
I don't have a timeline for this at this moment. Sorry.
Closing this issue per above comment.
Amplify re-configuration feature request is tracked here: https://github.com/aws-amplify/amplify-flutter/issues/1208
Please feel free to reopen if any follow ups are needed.