Skip to content
This repository was archived by the owner on Jun 3, 2020. It is now read-only.

Wouldn't this be an expensive query? #1

Open
nubpro opened this issue May 13, 2020 · 5 comments
Open

Wouldn't this be an expensive query? #1

nubpro opened this issue May 13, 2020 · 5 comments
Assignees
Labels
question Further information is requested

Comments

@nubpro
Copy link

nubpro commented May 13, 2020

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?

@ferdingler ferdingler self-assigned this May 13, 2020
@ferdingler ferdingler added the question Further information is requested label May 13, 2020
@ferdingler
Copy link
Contributor

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.

@nubpro
Copy link
Author

nubpro commented May 16, 2020

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

@ferdingler
Copy link
Contributor

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!

@nubpro
Copy link
Author

nubpro commented May 22, 2020

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?

@ferdingler
Copy link
Contributor

ferdingler commented May 25, 2020

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants