Skip to content
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

Provide method to clear and full sync specific models #1711

Open
1 task done
PS-MS opened this issue Apr 22, 2022 · 1 comment
Open
1 task done

Provide method to clear and full sync specific models #1711

PS-MS opened this issue Apr 22, 2022 · 1 comment
Labels
datastore DataStore category/plugins feature-request Request a new feature

Comments

@PS-MS
Copy link

PS-MS commented Apr 22, 2022

Before opening, please confirm:

Language and Async Model

Kotlin

Amplify Categories

DataStore

Gradle script dependencies

    def amplify_version = "1.32.1"
    def amplify_kotlin_version = "0.16.0"

    implementation "com.amplifyframework:core-kotlin:$amplify_kotlin_version"
    implementation "com.amplifyframework:aws-storage-s3:$amplify_version"
    implementation "com.amplifyframework:aws-auth-cognito:$amplify_version"
    implementation "com.amplifyframework:aws-api:$amplify_version"
    implementation "com.amplifyframework:aws-datastore:$amplify_version"

Please include any relevant guides or documentation you're referencing

https://docs.amplify.aws/lib/datastore/sync/q/platform/android/#clear-local-data
https://docs.amplify.aws/lib/datastore/sync/q/platform/android/#reevaluate-expressions-at-runtime

Describe the feature request

I'm currently working on a feature to allow set roles and permissions and cannot clear or full sync a specific model if needed at runtime.

var syncPosts: Boolean = false

fun initialize() {
    Amplify.addPlugin(AWSDataStorePlugin.builder().dataStoreConfiguration(
        DataStoreConfiguration.builder()
            .syncExpression(Post::class.java) {
                                if (syncPosts) {
                                    QueryPredicates.all()
                                } else QueryPredicates.none()
                            }
            .build())
        .build())
}

fun changeSync() {
    syncPosts = true;
    Amplify.DataStore.stop(
        {
            Amplify.DataStore.start(
                { Log.i("MyAmplifyApp", "DataStore started") },
                { Log.e("MyAmplifyApp", "Error starting DataStore", it) }
            )
        },
        { Log.e("MyAmplifyApp", "Error stopping DataStore", it) }
    )
}

To use the documentation examples, initially this user isn't allowed to use any Posts. The app will start up, full sync Posts (giving nothing) and sets the LastSyncMetadata saying this model has been synced.

A GraphQL mutation is observed and the user is now allowed to view Posts, so changeSync() is called setting the syncPosts flag and restarting datastore (stop & start, not clear).

I would expect the Post model to retrieve all of the posts, as that is now the predicate, not just the posts that were updated since the last sync attempt.

A GraphQL mutation is observed and the user is now NOT allowed to view Posts again, unfortunately the only way to remove all Post from the local data is a DataStore.clear() but this clears the whole database, which contains wanted information and would require a complete database sync again.

Summary:

  • I would like a way to perform a full sync on a specific model
  • I would like a way to clear a specific model
@sdhuka sdhuka added datastore DataStore category/plugins feature-request Request a new feature labels Apr 22, 2022
@PS-MS
Copy link
Author

PS-MS commented May 5, 2022

Is it correct that changing the syncExpression from none() to all() should only sync the changes since the expression update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datastore DataStore category/plugins feature-request Request a new feature
Projects
None yet
Development

No branches or pull requests

2 participants