Firebase 限制每個客戶端 100 個快照偵聽器。我有一個名為“MyChats”的螢屏,它顯示用戶擁有的所有聊天記錄并想知道以下內容:
- 我的下面的函式,它獲取螢屏的資料,是否只是一個監聽器?
- 獲取每個聊天室的最新訊息(在預覽中列出,類似于 Whatsapp、FB Messenger 和其他聊天應用程式)會影響我的聽眾數量嗎?
firestore
.collection("chats")
.where("membersArray", "array-contains", currentUser.uid)
.where("deletedAt", "==", null)
.orderBy("lastMessage.date")
.startAt(new Date())
.onSnapshot(...);

uj5u.com熱心網友回復:
我的下面的函式,它獲取螢屏的資料,是否只是一個監聽器?
你只打電話onSnapshot()一次,所以只有 1 個聽眾。
獲取每個聊天室的最新訊息會影響我的聽眾數量嗎?
如果您指的是上面的代碼,那只是一個帶有 1 個偵聽器的查詢。如果您為每個檔案單獨添加一個偵聽器,那么這將是 N 個偵聽器。
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(...)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/518680.html
標籤:Google Cloud Collective 扑火力基地谷歌云火库
