firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.62k stars 1.83k forks source link

Pagination with realtime data in FireStore #1524

Open dovahkiin98 opened 5 years ago

dovahkiin98 commented 5 years ago

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?

samtstern commented 5 years ago

@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?

dovahkiin98 commented 5 years ago

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.

samtstern commented 5 years ago

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." ?

dovahkiin98 commented 5 years ago

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.

jonthn90 commented 5 years ago

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.

RubyLichtenstein commented 5 years ago

please check my implementation for real time pagination

https://github.com/RubyLichtenstein/FireCat

@dovahkiin98

sabeehshah commented 4 years ago

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

jonthn90 commented 4 years ago

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