[Request] DataStore models should have a sync status field
See original GitHub issueIs 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:
- Created 3 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top GitHub Comments
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.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.