awslabs / awslabs/aws-mobile-appsync-sdk-android
Delta sync base query always runs again after process restart
- Dominant language
- Java
- Stars
- 106
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the bug**
The base query executes regardless of whether the elapsed time exceeds the configured base refresh interval, if the process is restarted. This is because the cache key used is unstable and based on `toString()`.
The specific API in use here is:
```
com.amazonaws.mobileconnectors.appsync.AWSAppSyncClient#sync(com.apollographql.apollo.api.Query, com.apollographql.apollo.GraphQLCall.Callback, com.apollographql.apollo.api.Subscription, com.amazonaws.mobileconnectors.appsync.AppSyncSubscriptionCall.Callback, com.apollographql.apollo.api.Query, com.apollographql.apollo.GraphQLCall.Callback, long)
```
**To Reproduce**
- Configure a delta sync operation with a base query, subscription, and delta, and base refresh interval of 10 minutes
- Run the `sync` operation, awaiting a successful base response
- Kill the Android process
- Reopen the app
- Run the `sync` operation again within 10 minutes of the first sync
**Expected behavior**
When running the app for the second time, the delta query is executed because the base refresh interval has not elapsed.
**Actual behavior**
The base query is executed again, because the database key is unstable and will never match the previous process instance.
**Environment(please complete the following information):**
- AppSync SDK Version: `2.10.0`
**Device Information (please complete the following information):**
- Device: Pixel 2 x86 Android Emulator, API `28`
- Android Version: API `28`
- Specific to simulators: Pixel 2 x86
**Additional context**
The SQLite database key used to store the `last_run_time` of a delta sync operation is generated using string concatenation of the queries and subscriptions `toString()` values, resulting in an unstable value that is unusable between process instances.
Example key:
```
com.example.appsync.generated.AllEventsQuery@e2e512dcom.example.appsync.generated.OnDeltaEventSubscription@c427662com.example.appsync.generated.AllEventsDeltaQuery@a2a73f3
```
I would expect the key to be based on the GraphQL query snippets themselves.
Contributor guide
Research direction
Start at AWSAppSyncClient#sync and trace how the SQLite last_run_time key is built from the query and subscription objects. Reproduce the restart scenario with a 10-minute base refresh interval, then verify that the key remains stable across process instances and the delta query runs before the interval expires.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, graphql, java, sqlite
- Domain
- api, databases, mobile-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100