1

我有一次查詢並且不想保留一個偵聽器,以便在發送手動觸發器時數據更新。Firebase在與addListenerForSingleValueEvent()一起使用時返回舊數據集

所以我的查詢是這樣的:

var ref = this.instance.child('/user/manish/today/events') 
    .orderByChild('endDateTime') 
    .endAt(endEventTime) 
    .limitToLast(10) 
    .addListenerForSingleValueEvent(this.previousEventListeners); 


    this.previousEventListeners = new com.google.firebase.database.ValueEventListener({ 
     onDataChange: (snapshot) => { 
     console.log("Value from native firebase access"); 
     console.dump(this.testing(snapshot.getValue())); 
     let result = { 
      value : this.testing(snapshot.getValue()), 
      type : "ValueChanged" 
     }; 
     console.dump(result); 
     }, 
     onCancelled: (databaseError) => { 
     console.log(databaseError.getMessage()); 
     hideActivtiyIndicator(); 
     } 
    }); 

返回即使追加新的記錄匹配查詢條件相同的數據集。

謝謝

+0

這很可能是您使用磁盤持久性。 Firebase的磁盤持久性和「addListenerForSingleValueEvent()」不能很好地混合。請參閱http://stackoverflow.com/questions/34486417/firebase-offline-capabilities-and-addlistenerforsinglevalueevent/34487195#34487195 –

回答

4

是的,我們經歷了我們自己的應用程序這種行爲。如果您需要啓用磁盤持久性的最新數據,則需要訂閱所有事件值更新,而不只是調用一個值。它特別令人困惑,因爲儘管存在這種行爲,Firebase仍然會呼叫服務器以獲得新的價值 - 它只是不會將這一項返還給您!

我向Firebase提出了關於此問題的支持請求,他們表示這是預期的行爲。我還建議他們澄清文件,他們說Thanks for this comprehensive feedback. We do value this kind of inputs from the developers. This will be included in our feature request list and will be discussed with our engineers. Unfortunately, I can't share any timeline or definite details as this will be monitored internally.

希望澄清的情況。對於它的價值,我們用FIRDatabaseReference類別(iOS,對您的平臺使用適當的隱喻)解決了這個問題,它增加了一個額外的功能。它調用SingleValueEvent,然後在500毫秒後再次調用它,同時將值返回給調用者。 (在此期間呼叫者消失的情況下,回調採用較弱的參考值)。500毫秒似乎很合適 - 用戶可以立即獲得顯示值,並且如果它們處於脫機狀態或網絡速度較慢,那麼他們看到的全部。但是,如果他們在線並且有良好的網絡訪問權限,那麼他們很快就會爲他們提供最新的數據。

相關問題