-
-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Optimize Document, if it was already fetched from Collection #45
Comments
I find this somewhat hypothetical. I know for a fact that the Firebase JS SDK has a lot of optimisations and caching, although I don't know the details. Thinking about it, I would preferable see this kind of caching inside the Firebase JS SDK, as it already does some level of caching and it could do that the most efficiently. |
This type of caching is already part of the sdk on ios, android and web. On react native for example you can verify this by disabling network:
And fetching any of the documents that are part of some you fetched before. You will still get the desired result. Snapshot.metadata will have the from_cache property set to true. |
@RWOverdijk how can I verify, that making this:
will not make 2 requests on backend? |
One of many ways. Enable debug, check your usage in the firebase console, log the metadata... A single listener, even if there's nothing new remote does seem to register as a read, but that's a different point entirely. In any case your question should probably be, "how can I verify that this doesn't make two requests in firestore", because that's what's responsible for this. |
@RWOverdijk but your original point to "enablePersistence" and check it with "disableNetwork" is totally about different type of cache. I think that native sdk don't have feautre, originally requested in this issue. |
@Strate The native sdks have those features. Unless I'm still not getting the question 😄 |
@RWOverdijk nvm, I am currently use my own re-implementation of firestoreter with reuse of collection/documents references :) |
@Strate All right. If you ever find a way to measure it do share. I find it hard to see a different way of doing it. |
I want to suggest enhancement, which can be useful to optimize usage of Firestore.
Imagine, you get collection of documents:
and after that, somewhere in your app, you want to get document by id:
Even if your document was already fetched from firestore, you will fetch it again, and subscribe to updates again. This can lead to non-optimal usage of firestore - you do more reads from db, than neccessary.
I think firestorter can have global map with all loaded document's data, and if developer creates Document, which was already loaded, reuse it.
The text was updated successfully, but these errors were encountered: