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

Amplify Sync Expression - to sort by provided field #1545

Open
manbalagan opened this issue Oct 19, 2021 · 6 comments
Open

Amplify Sync Expression - to sort by provided field #1545

manbalagan opened this issue Oct 19, 2021 · 6 comments
Labels
datastore DataStore category/plugins feature-request Request a new feature

Comments

@manbalagan
Copy link

manbalagan commented Oct 19, 2021

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 #1430 (comment)

@poojamat
Copy link
Contributor

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.

@poojamat poojamat assigned poojamat and unassigned poojamat Oct 27, 2021
@poojamat poojamat added datastore DataStore category/plugins feature-request Request a new feature labels Oct 27, 2021
@manbalagan
Copy link
Author

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....");
                        }
                    });

                }
            }
    );

@poojamat
Copy link
Contributor

poojamat commented Nov 1, 2021

Unfortunately there is no way to set this time out at this time. We will put this is a feature request as well.

@manbalagan
Copy link
Author

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.

@KevinLam0308
Copy link

KevinLam0308 commented Mar 9, 2022

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!

@manbalagan
Copy link
Author

@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 ?

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

3 participants