Firebase has a limit of 100 snapshot listeners per client. I have a Screen called "MyChats" which displays all the chats a user has and wanted to know the following:
- Is my below function, which gets the data for the screen, counting as just a single listener?
- Would grabbing the latest message for each chatroom (to list it in a preview, similar to Whatsapp, FB Messenger and other chat applications) affect my number of listeners?
firestore
.collection("chats")
.where("membersArray", "array-contains", currentUser.uid)
.where("deletedAt", "==", null)
.orderBy("lastMessage.date")
.startAt(new Date())
.onSnapshot(...);
CodePudding user response:
Is my below function, which gets the data for the screen, counting as just a single listener?
You are calling onSnapshot()
only once so that's only 1 listener.
Would grabbing the latest message for each chatroom affect my number of listeners?
If you are referring to above code, that's just a single query with 1 listener. If you individually add a listener for each document then that'll be N listeners.
const col = db.collection("chats");
// 1 listener irrespective of number of documents in collection
col.onSnapshot(...)
// 3 listeners, as they are assigned separately
col.doc("1").onSnapshot(...)
col.doc("2").onSnapshot(...)
col.doc("3").onSnapshot(...)