I\'ve noticed, when I try to use a realtime listener on a Collection in firestore, each time a new Document is added to the collection, the logic will be rerun, and I will d
The documents are cached and hence they are not completly downloaded. But if the complete data is bigger than cache size, it might be ree downloaded. The best strategy is to enable cache storage to disk and then using limitToLast(1).
firebase.firestore().collection("Tweets")
.orderBy("key1")
.limitToLast(1)
.onSnapshot(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
console.log("snapshot added ", doc)
});
});
in this key1 could be the tweet id.
This will leverage automatic single property index and will only fetch the last record. if persistence is enabled, this fetch will be from the cache.
Multiple answers above have talked about how to figure about if this data is new or stale.