aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 245 forks source link

Amplify how to stop auto sync feature for Specific models #1671

Closed sagar-sable closed 1 year ago

sagar-sable commented 2 years ago

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?

HuiSF commented 2 years ago

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?

sagar-sable commented 2 years ago

SALES_LIST

it is a field of type list in the "AllRetailerList" model

sagar-sable commented 2 years ago

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?

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.

HuiSF commented 2 years ago

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:

sagar-sable commented 2 years ago

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

sagar-sable commented 2 years ago

@HuiSF also will there be any feature coming soon for Amplify Re-Configuration?

HuiSF commented 2 years ago

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.

  1. DataStore performs full sync (sync all syncable data from AppSync) on each fresh start (newly installed App e.g.)
  2. 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 larger syncInterval according to your use case.
  3. 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)
  4. When changes are made to other records in cloud, the new changes will be synced into your device
    1. When you cold start the App the new changes are synced via delta sync or full sync
    2. 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.

HuiSF commented 1 year ago

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.