aws-amplify / aws-amplify/amplify-android
Provide method to clear and full sync specific models
- Dominant language
- Java
- Stars
- 287
- Forks
- 132
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 45
Description
### Before opening, please confirm:
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-android/issues?q=is%3Aissue+) and [discussions](https://github.com/aws-amplify/amplify-android/discussions).
### Language and Async Model
Kotlin
### Amplify Categories
DataStore
### Gradle script dependencies
```groovy
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
Contributor guide
Research direction
Start with the linked DataStore documentation for clearing local data and reevaluating sync expressions, then trace the existing stop/start and clear behavior described in the issue. Done means callers can full-sync or clear one model without clearing unrelated local data or forcing a complete database resync.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- database
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100