Home > Software design >  What is the cost for this Firestore onSnapshot listener?
What is the cost for this Firestore onSnapshot listener?

Time:07-18

I'm trying to get the sync status of a collection in Firestore. with the following query snapshot.

firebase.firestore().collection("cities").onSnapshot(
  { includeMetadataChanges: true },
  (querySnapshot) => {
    setHasPendingWrites(querySnapshot.metadata.hasPendingWrites);
  }
);

Does this listener cost me additionally? (than my read/write/update/delete queries to Firestore)

CodePudding user response:

It will cost you initially one read for every document in "cities", then one read every time one of those documents is added, updated, or deleted as long as the listener is still active. It is not different than any other listening query.

Specifying includeMetadataChanges doesn't cost anything extra, if that's what you're asking. The extra metadata about the pending writes comes from the local app persistence layer managed by the SDK and does not require any additional data from the Firestore backend.

  • Related