aws-amplify / amplify-swift

A declarative library for application development using cloud services.
Apache License 2.0
462 stars 198 forks source link

Define model sync priority #1155

Open damienpontifex opened 3 years ago

damienpontifex commented 3 years ago

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

Some of our models are essential for display on the initial screen a user sees. Other data is more of a nice to have as it requires deeper navigation. Equally some of this deeper data is significantly larger.

Syncing seems to happen all together, or maybe indeterminate is a better way to describe it

Describe the solution you'd like We'd want to define a high, medium and low priority of model entities as they'd be synced.

Say it was a music app where we sync song names and for whatever reason, their lyrics are a separate model. Something like

ModelRegistry.register(modelType: Song.self, priority: .high)
ModelRegistry.register(modelType: SongLyrics.self, priority: .low)

To also be clear, we still want to sync all the data, just that some of it would be preferable to be available ASAP vs others at the background rate would be fine

Describe alternatives you've considered N/A

palpatim commented 3 years ago

Note for future: This feature request would have to be balanced against the need to sync the models by their relationship dependencies. In the above example, if "Song" has a 1:many relationship with "SongLyrics", then we'd have to sync SongLyrics first, regardless of their relative priorities, in order to maintain referential integrity.

damienpontifex commented 3 years ago

Seems to have a similar desired outcome as #1106

palpatim commented 3 years ago

Seems to have a similar desired outcome as #1106

I don't follow that, except insofar as the desired outcome is "all my data syncs"? It seems that #1106 is related to a max subscription error, as opposed to this request being about prioritizing subscriptions so they can be fulfilled in a customizable order.

ashiemke commented 3 years ago

I'd also like this... I thought I could create something similar with sync expressions (basically return a predicate like model.keys.owner == ready?userId:"bogus"), but that doesn't seem to work due to https://github.com/aws-amplify/amplify-ios/issues/1177

This would be super useful and I don't see a way to work around it.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open for 14 days with no activity. Please, provide an update or it will be automatically closed in 7 days.

ChadyG commented 3 years ago

This would be ideal. In our scenario, one of our most necessary items is the User table. This table doesn't have any dependencies but gets relegated to the end of the sync due to the alphabetical sort in the sortByDependencyOrder method. It would be great if this initial sorting was adapted to utilize a user-preference priority as suggested here.

ChadyG commented 1 year ago

Anything that can be done to help progress this?
This is definitely a recurring issue for our users as they switch phones, receive app updates with new schemas, etc. The more data they accrue the longer they have to wait until the app can be used since we must wait until user and profile are synced. Add in data sync only running in the foreground and you end up with a decent number of people that call in frustrated.

fzy-github commented 9 months ago

I wonder if there could be some sort of config option that we could make to to eg. mark certain models to be synced in batches. Say eg. models that do not have relationships could be batched, and the onees with relationship woul still rely on one-by-one syncing...