0

Is firestore optimized for read by reading only the values that have changed since the last read ?

  • Firestore client maintains a local cache.
  • Documents in the cache have metadata with an update timestamp which I assume is the update time stamp on the server and not a local timestamp.
  • Firestore reads cost money.

If all the above holds true, it would make sense for firestore sdk to not re-read documents that have not been updated since the last read, to be more efficient bandwidth wise and dollar wise.

Do firestore optimize this by default or does it requery everything ?

Ced
  • 15,847
  • 14
  • 87
  • 146
  • Does this answer your question? [How to avoid unnecessary Firestore reads with Cache](https://stackoverflow.com/questions/52700648/how-to-avoid-unnecessary-firestore-reads-with-cache) – Gastón Schabas May 27 '23 at 23:39

1 Answers1

3

Firestore only queries for changed documents, using a mechanism known as a resume token. Results from the server include this token which can be used to resume the query at a later time. This implicitly asks for changes since the last query.

However, after 30 minutes, the server stops tracking changes to the query on behalf of the client (to conserve resources). When a client resumes after this point, the server has to re-run the whole query to see what changed.

The problem with just querying for a last-modified timestamp is that you won't see any document deletions. A secondary problem is that creating an index on such a timestamp necessarily limits throughput to the collection to about 500 writes/second.

source: https://github.com/firebase/firebase-js-sdk/issues/3422

Ced
  • 15,847
  • 14
  • 87
  • 146