第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

通過 DocumentReference 監(jiān)聽 firestore 時(shí)將打開多少個(gè)套接字

通過 DocumentReference 監(jiān)聽 firestore 時(shí)將打開多少個(gè)套接字

C#
翻閱古今 2023-09-16 14:58:01
我是 Cloud Firestore 的新手。當(dāng)我閱讀文檔時(shí),我看到了下面的代碼:DocumentReference docRef = db.Collection("cities").Document("SF");FirestoreChangeListener listener = docRef.Listen(snapshot =>{    Console.WriteLine("Callback received document snapshot.");    Console.WriteLine("Document exists? {0}", snapshot.Exists);    if (snapshot.Exists)    {        Console.WriteLine("Document data for {0} document:", snapshot.Id);        Dictionary<string, object> city = snapshot.ToDictionary();        foreach (KeyValuePair<string, object> pair in city)        {            Console.WriteLine("{0}: {1}", pair.Key, pair.Value);        }    }});實(shí)際上,我知道如何通過過濾查詢進(jìn)行偵聽并偵聽查詢快照中的所有 300 條記錄,但是即使只有一個(gè)文檔更新,查詢也會(huì)讀取所有記錄,并且會(huì)顯著增加讀取計(jì)數(shù)(成本也會(huì)增加)。如果我有 300 個(gè)文檔,并且我想通過文檔參考快照收聽所有文檔的實(shí)時(shí)更新,該怎么辦? 會(huì)有 300 個(gè)獨(dú)立的套接字還是一個(gè)單例套接字來監(jiān)聽所有這些套接字。C# 驅(qū)動(dòng)程序和 Flutter 驅(qū)動(dòng)程序行為相同嗎?實(shí)施將是這樣的;foreach (var docRef in docRefList) //300 records{    FirestoreChangeListener listener = docRef.Listen(snapshot =>    {        Console.WriteLine("Callback received document snapshot.");        Console.WriteLine("Document exists? {0}", snapshot.Exists);        if (snapshot.Exists)        {            Console.WriteLine("Document data for {0} document:", snapshot.Id);            Dictionary<string, object> city = snapshot.ToDictionary();            foreach (KeyValuePair<string, object> pair in city)            {                Console.WriteLine("{0}: {1}", pair.Key, pair.Value);            }        }    });}
查看完整描述

1 回答

?
RISEBY

TA貢獻(xiàn)1856條經(jīng)驗(yàn) 獲得超5個(gè)贊

當(dāng)您與 Firebase 實(shí)時(shí)數(shù)據(jù)庫交互時(shí),您的應(yīng)用程序和 Firebase 服務(wù)器之間會(huì)打開一個(gè)套接字連接。從那時(shí)起,應(yīng)用程序和數(shù)據(jù)庫之間的所有流量都通過同一個(gè)套接字。因此,無論您創(chuàng)建實(shí)時(shí)數(shù)據(jù)庫實(shí)例多少次,它始終是單個(gè)連接。

另一方面,根據(jù) @Frank van Puffelen 的評(píng)論,當(dāng)您與 Cloud Firestore 數(shù)據(jù)庫交互時(shí),客戶端使用 HTTP/2 連接而不是 Web 套接字連接到 Firestore。HTTP/2 和 Web 套接字都通過單個(gè)連接發(fā)送多個(gè)請(qǐng)求。

如果一段時(shí)間內(nèi)沒有活動(dòng)監(jiān)聽器,Cloud Firestore 客戶端會(huì)自動(dòng)關(guān)閉連接,但當(dāng)您附加監(jiān)聽器或再次執(zhí)行讀/寫操作時(shí),它會(huì)重新打開連接。


查看完整回答
反對(duì) 回復(fù) 2023-09-16
  • 1 回答
  • 0 關(guān)注
  • 99 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)