2017-06-03 122 views
0

這是一個聊天應用程序。我正在檢索消息以顯示在聊天室recyclerview上。爲此,我使用了FirebaseRecyclerAdapter。我正在檢索最新的500條消息。並且該聊天室有超過20k條消息。當我加載該活動時,需要6秒鐘才能加載所有500條消息。從Firebase數據庫檢索數據時的延遲

我跟蹤了時間。

延遲在setAdapter和RecyclerAdapter類之間。

我的消息結構在火力地堡數據庫

{ 
    "-KlQc42ici0_PRCBX7-V" : { 
    "message" : "message 1", 
    "timestamp" : 1496185853436, 
    "type" : "action", 
    "username" : "berkleef2", 
    }, 
    "-KlQmhcwK96j30FNoSs-" : { 
    "message" : "message 2", 
    "timestamp" : 1496188640000, 
    "type" : "action", 
    "username" : "atrickrodney16yahoocomat", 
    "zread" : true 
    }, 
    "-KlQmjSoucJD7uaHriOh" : { 
    "message" : "message 3", 
    "timestamp" : 1496188647083, 
    "type" : "text", 
    "username" : "atrickrodney16yahoocomat", 
    "zread" : true 
    } 
} 

延遲setAdapter

mNewAdapter = new NewChatRecyclerAdapter(
        ChatMessageItem.class, 
        R.layout.message_item, 
        RecyclerView.ViewHolder.class, ref.limitToLast(500), Fusername, booIsPrivateChat, chatd, strOpponent); 
      messageList.setAdapter(mNewAdapter); 

後,開始我認爲這是與適配器類沒有問題。所以如果問題是加載500條消息。那麼我應該在這種情況下做加載聊天消息...啓用了

回答

0

使用火力地堡脫機功能設置的持久性,讓您可以存儲您的郵件

+0

持久性已啓用。但是,當我重新啓動應用程序相同的結果... – Bucky

0

可以在20周或50的消息一大塊獲取它們之後。

+0

如何在FIrebase中做到這一點? – Bucky

+0

@Bucky檢查一下:https://github.com/firebase/FirebaseUI-Android/pull/26 –

0

您可以使用由您的數據庫引用的firebase數據庫提供的keepsynced函數。

相關問題