aws-appsync-refarch-offline icon indicating copy to clipboard operation
aws-appsync-refarch-offline copied to clipboard

Wouldn't this be an expensive query?

Open nubpro opened this issue 5 years ago • 5 comments

https://github.com/aws-samples/aws-appsync-refarch-offline/blob/master/src/components/Orders/index.js

I noticed that you subscribed to the Order model in line 15 and its purpose is to re-query all the orders again and re-sort them.

So for every new order or changes to an order, you would do this all over again. Say in a minute, there's over 100 changes to the respective orders, wouldn't this impact the overall performance of the app?


To that, I would like to continue my conversation over from here. In my usecase, after a user logs out and relogs back in, querying the Order model doesn't yield any results at all. But instead, using the subscription, it would return each and every orders. For every orders, I had to query the Order model to get all orders again and like the example given, I would re-sort them every time. Isn't that overkill?

nubpro avatar May 13 '20 15:05 nubpro

Hi @nubpro, this is a good observation, let me add some thoughts:

DataStore.query always goes against local data, so it is not an expensive operation in terms of network activity. However, the refetch function in the Orders/index.js may be expensive in terms of compute for the mobile device, as you point out it is sorting all orders and then re-rendering the entire list every time. In that sense I agree with you, you could potentially make that flow more efficient by only appending or modifying the Order that we get as parameter in the DataStore.observe function as opposed to replacing the entire list over and over.

ferdingler avatar May 13 '20 20:05 ferdingler

@ferdingler Thanks for the reply!

Can we expect DataStore.observe to fetch data in order of their inserted or updated sequence?

In other hand, I think there are syncing issue with Datastore, everytime I would hot reload my app in React Native. The DataStore.observe would be triggered and returning me data that I have already have during the initiation of DataStore.query. There is no way to it, is it? Or it's just a me thing?

nubpro avatar May 16 '20 09:05 nubpro

Hi @nubpro , order preservation is not guaranteed in DataStore.observe. The protocol is focused on convergence and correctness.

DataStore.observe reacts to changes that are written to the storage engine. This can be results of base sync, delta sync, mutations or subscriptions. This architecture is what allows the developer to not have to think about the syncing details.

I hope this helps clarify!

ferdingler avatar May 20 '20 22:05 ferdingler

Thanks again!

Whenever my client is syncing with the backend, then I perform a DataStore.query, it requests never gets completed. The promise never resolves.

Therefore, we're always stuck in the loading screen. It is a design flaw with DataStore?

nubpro avatar May 22 '20 10:05 nubpro

Hi, DataStore.query works correctly for me. If you think you have a Bug to report, please feel free to do so here: https://github.com/aws-amplify/amplify-js/issues.

ferdingler avatar May 25 '20 20:05 ferdingler