question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Request] DataStore models should have a sync status field

See original GitHub issue

Is your feature request related to a problem? Please describe.

it’s a very common need to want to indicate the sync status of datastore items. i understand its a distsys issue. but we need to offer some sort of documentation or blessed path for people to show whether something has been “synced to cloud” or is really “local only and can be lost” eg during a model migration.

we seem to have this process here that quite honestly i dont understand (what am i executing “against the remote state”?): https://docs.amplify.aws/lib/datastore/sync/q/platform/js#update-and-delete-with-predicate

Either we do it for people and warn of edge cases, or they do it themselves and do it badly.

Describe the solution you’d like

check a field or run a method. MYMODELINSTANCE.isSynced() === true or false

Describe alternatives you’ve considered

firebase uses a CompletionListener callback https://stackoverflow.com/a/48565275/1106414

Additional context

Jameson says:

The trouble is - which version has been synced to the cloud? It is, at its core, the classic cache coherency problem. Even to answer “is it still on the server (not deleted),” you’d have to go ask the server, to be sure. But, for the purposes of the UI: when you save to DataStore, mark an ID in a Set. Then, listen to Hub, for an event that lets you know it has been published. When it is, remove from set, and update UI from Set. This will be right most of the time, assuming a 1 client 1 server relationship for a given ID.

Amplify.Hub.subscribe(
    HubChannel.DATASTORE,
    event -> {
        return DataStoreChannelEventName.PUBLISHED_TO_CLOUD.toString().equals(event.getName());
    },
    event -> {
        ModelWithMetadata<?> mwm = (ModelWithMetadata<?>) event.getData();
        set.put(mwm.getModelId());
    invalidateModel(set);
    }
);

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
sw-yxcommented, Nov 6, 2020

imo, no - @mauerbac do you mind reopening this? the documentation was only one small part. the developer experience is still not good enough if we are asking people to listen to Hub for such a basic item. i think you and i are agreed on that, remains to be seen if the maintainers agree.

1reaction
meducaticommented, Nov 26, 2020

Late to the party, but was just searching the docs for exactly this feature. Hope we can get this implemented.

Use case: My client want to go offline for long periods of time on his tablet. He will stay signed in but open/close the (web-)app frequently. When he eventually logs out, it would be great with an easy request to the local Datastore to make sure that there are no pending items that are waiting to try synchronization to DynamoDB.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NEW in Amplify DataStore: Selective sync and sort functionality
Selectively sync your app data based on active functionality​​ By default, DataStore downloads the entire contents of your cloud data source to ...
Read more >
DataStore - Syncing data to cloud - Flutter - AWS Amplify Docs
Learn more about how DataStore connects to an AppSync backend and automatically syncs all locally saved data using GraphQL. - Flutter - AWS...
Read more >
Exporting and Importing Entities - Datastore - Google Cloud
Per-entity property value index settings are exported and honored during ... If you need to import only a subset of entities or need...
Read more >
Sync-enabled feature services—ArcGIS REST APIs
If supportsRegisteringExistingData is true, the createReplica operation has a replicaOptions parameter that supports registering existing data. This allows a ...
Read more >
Sync Records using a Record Action - Appian 22.3
Get the record identifiers of orders placed in the Northwest sales region this month. Create a process model with the Sync Records smart...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found