Love to Code
Love to Code

Reputation: 463

Do Observables re-query ALL data when Firestore fields update?

Let's say I do a query against a Firestore collection over a date range or something. If I get an observable to the set of documents and iterate through it to build up a local collection, will it re-read all the data from Firestore every time there is a change in Firestore? Say this observable is from a where clause that contains 500 documents and I iterate through doing something:

   this.firestoreObservable$.subscribe(documents => {
      documents.forEach(async doc => {
         // do something
      })
   })

If one field on one documents change on Firestore, will that count as another 500 document reads? If so (ouch!) what would the recommenced best practice be to keep from spending so many reads?

Thanks.

Upvotes: 0

Views: 141

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317552

No. If only one document changes, then it will cost only one read. The entire set of documents is cached in memory as long as the query is actively listening to updates, and the SDK will deliver you the cached results in addition to whatever actually changed.

If the query ends and a new one starts up, then you will be charged for the full set of results again.

Upvotes: 2

Related Questions