0

I'm building a chat app. There's a particular node in my Firebase database which stores a conversation this user has had with another person(a List of messages.) I'm loading these messages on my app using a FirebaseRecyclerAdapter which is a part of FirebaseUI. It works very well, but I'm worried about scaling. If a conversation were to say have 20,000 + messages(which many conversations do!) will it load? Does Firebase load this data from the Firebase Database all at once or in batches?
If no how exactly do I load data in batches into a RecylcerView(If there are 1000 items, initially 1000 - 980, when the user scrolls up 980 - 960 etc.) I understand that I can use the endAt() and limitToLast() functions to load data in batches into the data source(ArrayList) but how do I implement a RecyclerView that loads from this in batches?

    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
    linearLayoutManager.setStackFromEnd(true);
    recyclerView.setLayoutManager(linearLayoutManager);
    final DatabaseReference databaseReference = /*Database Reference */ ;
    databaseReference.keepSynced(true);
    firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Chat, RecyclerView.ViewHolder>(Chat.class, R.layout.chat_message_received, RecyclerView.ViewHolder.class, databaseReference.orderByChild("timeStamp").getRef()) {
        //...Code
    };
    recyclerView.setAdapter(firebaseRecyclerAdapter);
    recyclerView.scrollToPosition(firebaseRecyclerAdapter.getItemCount() - 1);

1 Answers1

0

The FirebaseUI adapters load all data that you point them to through the Query or DatabaseReference that you pass in to the constructor. There is no built-in delayed loading or pagination.

Also see:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807