FirebaseUI-Android icon indicating copy to clipboard operation
FirebaseUI-Android copied to clipboard

Pagination with realtime data in FireStore

Open dovahkiin98 opened this issue 7 years ago • 8 comments

In the FireStore Adapter, there are 2 options: No paging, and paging. As said, the paging option doesn't offer realtime data, but the no paging option becomes time expensive when the data becomes large in an app like chatting apps.

Is there a way to get the best of both worlds?

dovahkiin98 avatar Nov 06 '18 12:11 dovahkiin98

@dovahkiin98 no, right now there is not. Can you describe your use case? Do you need:

  1. Just notifications for new items
  2. (1) and notifications when an existing item changes
  3. (1) and (2) and the ability for items to be re-ordered dynamically?

Or something else?

samtstern avatar Nov 06 '18 17:11 samtstern

Notifications for when items are added, changes, or removed. But also the ability to get pages, for example, receive each 50 items alone, not the whole block. I'm guessing the only way is to make a custom listener and change the limit dynamically, tho that didn't work well with me in Realtime database.

dovahkiin98 avatar Nov 06 '18 18:11 dovahkiin98

Can you explain what you mean by "But also the ability to get pages, for example, receive each 50 items alone, not the whole block." ?

samtstern avatar Nov 06 '18 20:11 samtstern

Getting all the data at once would take time, I want to be able to take pages instead of all the data. 50 messages a time, then add them to the list. But all the pages are real time. Listening to edits and deletions, while one page is listening to addition. Can the query for the adapter be updated after the items are laid out?

For example: I make the view listen for changes and deletion with a pagination adapter, while a snapshot listener listens for additions. But the pagination adapter isn't real time, so it only reads the data once right? If changes or deletions happen, the adapter won't be notified.

dovahkiin98 avatar Nov 06 '18 22:11 dovahkiin98

As @dovahkiin98 wrote, it could be great a way to get the best of both worlds.

I would appreciate it if this improvement is made in the future.

At the moment my solution was reload the adapter to my recyclerview.

jonthn90 avatar Jan 16 '19 02:01 jonthn90

please check my implementation for real time pagination

https://github.com/RubyLichtenstein/FireCat

@dovahkiin98

RubyLichtenstein avatar Mar 28 '19 12:03 RubyLichtenstein

@jonthn90 hey, can you explain if you found a solution on how to accomplish this while still using FirestorePagingAdapter?

sabeehshah avatar Mar 27 '20 10:03 sabeehshah

hi @sabeehshah. This was some time ago so I don't remember exactly how was solve :(. But I remember I implemented the pagination without the Real Time feature. And every time a user adds/removes an item, refresh the adapter to reload all the collection again. This was not the most eficcient but with the pagination don't reload all the colleccion just the number of items that you configurate in your pagination.

For Pagination

Manual implementation

https://firebase.google.com/docs/firestore/query-data/query-cursors

With Firebase UI (I used this)

https://github.com/firebase/FirebaseUI-Android/blob/master/firestore/README.md#using-the-firestorepagingadapter

jonthn90 avatar Mar 27 '20 17:03 jonthn90