aws-amplify / aws-amplify/amplify-android
Amplify Sync Expression - to sort by provided field
- Dominant language
- Java
- Stars
- 287
- Forks
- 132
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 45
Description
Problem : For chat application - for example, has 2 contacts with 5,000 messages each. If the sync expression syncMaxRecords is set to 5000, then messages from first contact gets synced and not for the second contact.
Expectation : Messages should be synced based on creation date (SortKey), so that latest 5000 messages gets synced irrespective of contacts.
Sync Expression:
` DataStoreSyncExpression consumerDataSyncExpression = () -> ConsumerData.INCARCERATE_ID.eq(siteIncaratedId);
DataStoreSyncExpression textMessageDataSyncExpression = () -> TextMessage.INCARCERATE_ID.eq(siteIncaratedId);
DataStoreConfiguration datastoreBuilder = DataStoreConfiguration.builder()
.errorHandler(STCDataStoreErrorHandler.instance())
.syncExpression(ConsumerData.class, consumerDataSyncExpression)
.syncExpression(TextMessage.class,textMessageDataSyncExpression)
.syncPageSize(1000)
.syncMaxRecords(25000)
.syncInterval(15, TimeUnit.SECONDS).build();
AWSDataStorePlugin dataStorePlugin = new AWSDataStorePlugin(datastoreBuilder);
Amplify.addPlugin(dataStorePlugin);`
GraphQL Schema
[schema.zip](https://github.com/aws-amplify/amplify-android/files/7376141/schema.zip)
Exception
DataStoreException{message=Initial sync during DataStore initialization failed., cause=java.util.concurrent.TimeoutException: Timed out while performing initial model sync., recoverySuggestion=There is a possibility that there is a bug if this error persists. Please take a look at
https://github.com/aws-amplify/amplify-android/issues to see if there are any existing issues that
Replying to Closed issue
Can I get code sample of what your graphQL schema and the sync expression looks like? I am under the impression that it _is_ supposed to sync based on a filter irrespective of which contact a message belongs in.
_Originally posted by @raphkim in https://github.com/aws-amplify/amplify-android/issues/1430#issuecomment-916415653_
Contributor guide
Research direction
Start by reproducing the initial sync with the schema.zip attachment and the DataStore sync expressions shown in the issue, using multiple contacts with more records than syncMaxRecords. Trace how syncMaxRecords and the model SortKey are handled; done means the newest 5000 matching messages are selected across contacts and the initial sync completes without the reported timeout.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- databases, mobile
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100