简体   繁体   中英

What is the cost for this Firestore onSnapshot listener?

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)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM