Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Does subscribing multiple times to the same collection or document trigger multiple reads? #2761

Answered by davideast
LanderBeeuwsaert asked this question in Q&A
Discussion options

Hi all,

suppose I do a subscribe in one component:

this.angularFirestore.collection('/my_collection')

and do the same subscribe in another component, will the second subscribe trigger extra reads?

What if I have a subscribe to:

this.angularFirestore.collection('/my_collection')

and have another subscribe to:

this.angularFirestore.doc('/my_collection/some_document')

Or

this.angularFirestore.collection('/my_collection')

and a filtered subscribe on the same collection:

this.angularFirestore.collection('/my_collection', (ref) => ref.where('some_filter', '==', 'some_value')
You must be logged in to vote

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.

Replies: 1 comment

Comment options

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.

You must be logged in to vote
0 replies
Answer selected by davideast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /