amplify-android
amplify-android copied to clipboard
Amplify Sync Expression - to sort by provided field
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
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
The data coming back from the sync query is ordered only by the hash key. Unfortunately we do not support specific sort during the sync operation. I will add this as feature request.
To overcome the time out - Is there a specific API that can override the time out of ~1 minute.
Currently I am doing a work around based on network status on datastore when the connection times out
Amplify.Hub.subscribe(
HubChannel.DATASTORE,
hubEvent -> DataStoreChannelEventName.NETWORK_STATUS.toString().equals(hubEvent.getName()),
hubEvent -> {
NetworkStatusEvent event = (NetworkStatusEvent) hubEvent.getData();
if(event.getActive()) {
Log.i("xxxx", "Datastore sync isActive ? : " + event.getActive());
}
else{
Log.i("xxxx", "Datastore sync isActive ? : " + event.getActive());
xxxx.runOnUiThread(new Runnable() {
@Override
public void run() {
isRetry.set(true);
loadContent(); // calls the Amplify.Datastore.query
Log.i("xxxx", "Timed out - Retrying....");
}
});
}
}
);
Unfortunately there is no way to set this time out at this time. We will put this is a feature request as well.
Is there an updated datastore library released for this feature request for syncing based on given criteria.
Expectation : Messages should be synced based on creation date (SortKey), so that latest 5000 messages gets synced irrespective of contacts.
I'm facing the similar issue and used the same workaround here, the sync time is over a minute at the first time syncing, here is the reported issue:
https://github.com/aws-amplify/amplify-js/discussions/9680
Ultimately, set a correct syncExpression to minimize the sync time and reset the timeout during syncing should be the best approach, please help to put this as a feature request also, thanks!
@poojamat Is there an issue created for taking this as a feature request ? Do you have a timeline on which version this would be released ?