简体   繁体   中英

Delay While Retrieving Data From Firebase Database

It's a chat app. I am retrieving messages to show on the chat room recyclerview. For that I'm using FirebaseRecyclerAdapter. I'm retrieving latest 500 messages. And that chat room has over 20k messages.. When I load that activity it is taking 6 seconds to load all 500 messages.

I tracked the time.

The delay was between setAdapter and RecyclerAdapter class.

My Message Structure In Firebase Database

{
  "-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
  }
}

The Delay Started after setAdapter

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

I think there is no problem with the adapter class. So if the problem is with loading 500 messages. Then what should I do in this case to load chat messages...

使用启用了Firebase脱机功能集的持久性,以便您可以存储消息

您可以一个接一个地以20或50条消息的块的形式获取它们。

您可以在数据库参考上使用keepsynced数据库提供的keepsynced函数。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM