onSnapshot() shared query results

193 views
Skip to first unread message

Wojciech Fiderek

unread,
Oct 8, 2019, 7:58:42 PM10/8/19
to Firebase Google Group
Hi everyone, I wonder if multiple onSnapshot listeners are sharing same data source (so database will not receive doubled read request).

Here is shortened example use case (when you want to have separate wrappers for onAdded and onRemoved):
firestoreDb.colection('colName').onSnapshot( (querySnap) => {
    querySnap
.docChanges( handleAdded )
});
firestoreDb
.colection('colName').onSnapshot( (querySnap) => {
    querySnap
.docChanges( handleRemoved )
});

If yes then what are constraints where queries data results are not shared between multiple onSnapshot listeners (eg. using where conditons OR documentSnapshots that not using querySnapshot result)?

Sam Stern

unread,
Oct 8, 2019, 8:03:44 PM10/8/19
to Firebase Google Group
Hi there,

Assuming those are on the same device, yes they share the same listener and the query will only happen once.  This is only the case because the queries are exactly the same.  If you have two different but potentially overlapping listeners, they will be totally separate read requests on the server.  They share the same offline cache, but that does not affect how the online reads are billed.

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/f66ab080-5c18-4e94-99e2-d6160f88aad5%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages