Does subscribing multiple times to the same collection or document trigger multiple reads? #2761
-
Hi all, suppose I do a subscribe in one component:
and do the same subscribe in another component, will the second subscribe trigger extra reads? What if I have a subscribe to:
and have another subscribe to:
Or
and a filtered subscribe on the same collection:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
It depends! In general the underlying Firestore SDK tries its best to use a cached result instead of going over the network. The protocol it uses also sends only the delta of the update. In your case if the records have not been modified since the previous subscription, there should be further reads. This is as long as the local cache is not cleared. In general you can assume that the Firestore SDK's cache is going to keep you from re-reading a document if it has not be updated. This caching behavior applies to |
Beta Was this translation helpful? Give feedback.
It depends! In general the underlying Firestore SDK tries its best to use a cached result instead of going over the network. The protocol it uses also sends only the delta of the update. In your case if the records have not been modified since the previous subscription, there should be further reads. This is as long as the local cache is not cleared.
In general you can assume that the Firestore SDK's cache is going to keep you from re-reading a document if it has not be updated. This caching behavior applies to
.onSnapshot()
but not.get()
calls.