-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider integration with Paging library once it is stable #5486
Comments
I've talked to @ericmaxwell2003 and he said he'll look into it later. |
Paging is 1.0 as of may 8th |
Yeah I have to do it here too Zhuinden/realm-monarchy#3 |
Any plans to support paging?! |
Slightly experimental, but Monarchy supports it now. DataSource.Factory<Integer, RealmDog> realmDataSourceFactory = monarchy.createDataSourceFactory(realm -> realm.where(RealmDog.class));
dataSourceFactory = realmDataSourceFactory.map(input -> Dog.create(input.getName()));
dogs = monarchy.findAllPagedWithChanges(realmDataSourceFactory,
new LivePagedListBuilder<>(dataSourceFactory, 20));
Well would you look at that, that's what Monarchy does 😄 I'm surprised I eventually sat down and made a library for it. |
@mhdtouban Out of curiosity, what is the use case for wanting to implement the Paging Library? With Realms lazy-loading architecture you don't actually need it since Realm doesn't have a cursor limit? |
It's for people who want to read pages of data from Realm on a background thread and passed to UI thread, instead of having lazy-accessed cursor where the actual read happens on UI thread. The cool thing is that this mechanism supports projection via |
@cmelchior I want to use paging for many reasons, first we now officially have a way for pagination in Android instead of relying on recycling view scroll listener which has downsides, second paging offers cool features like a placeholder and continuous loading mechanism etc. |
@Zhuinden I guess that is a valid point. I still haven't seen it being demonstrated as a problem in practice though, so IMO the problem is largely theoretical. But I guess the paging library also provides an abstraction for the underlying data source if you want to swap them later. @mhdtouban My point was that you don't need those loading mechanisms and placeholders with Realm. Our lazy-loading works very differently than how SQLite does it. |
Note, It isn't that we don't want to support paging, but I strongly suspect that the majority of cases don't actually need it and people are just using patterns from elsewhere that doesn't really apply to Realm. |
Am not quite sure I get you with "don't need those loading mechanisms with realm", let's say I want to fetch data through an API with pagination. How would realm help in lazy loading? I mean I understand that it will help if am hitting the database, but what if am getting the data from API? |
Personally I started investigating the background thread read because of this.
Technically you get the benefits of BoundaryCallback being called for zero items loaded and for item at end loaded. Previously you had to intercept zero-loaded in the Results change listener, and you had to know you reached the end if RecyclerView could no longer scroll down. BoundaryCallback does wrap these cases. |
@mhdtouban Sorry, I was mainly thinking about the use case where you had all data stored locally. I do agree that the paging library nicely provides a lot of utility where you need to fetch the data from the server first. |
Guys great work! Can I suggest examples explaining how exactly pagination is not needed with Realm?
I mean this problem of pagination with Realm gets most new users stumped, and there's no example! Most of the UI controls and grid/list display routines out there have callbacks that include query, sort parameters...and pagination parameters. It's clear the use case being referenced in your documentation is not sufficient to cater to the majority of pagination use cases out there. You do need a way to execute SKIP, TAKE, TOP, LIMIT routines. Thanks. |
Technically what they mean by not needing pagination is that data is lazy-loaded so that means you can access any item at any index, and that item will only be loaded on access. This lazy loading means that you don't need to "load more" because you can just throw everything into the list regardless of result size, and it'll be fine. But Realm doesn't actually support "SKIP" at this time. |
@Zhuinden However, I'm afraid my concerns were not addressed. For example, say you have this API or databound control that allows you implement a call back to retrieve a window of rows. That is after you have applied very specific sorting and filtering parameters to the data.
For emphasis, you cannot pass an List, Map, IQueryable to a control or API that is expecting a specific number of rows. If it's local data and you have to deal with pagination call backs, then Realm simply does not support pagination or so it seems. In the case of IQueryable, the documentation makes it clear that Skip, Take are not supported. You need a way to reason abount the logic of batching rows, it is the most popular use case. An example would have sufficed I think, you're assuming data pagination is not a valid use case. Thanks. |
Hi everyone, To be consistent and use support libraries, I'm wanting to implement Paging support library because I need to fetch data from the API when needed. Because previous comments are 5 months old, I just wanted to know if an official I think it would be nice to have one, like ObjectBox do for example. Thanks. |
Any update on this issue as it's very crucial. |
@deepakkumardk if your UI freezes on Also, Paging 3.x will be so vastly different from Paging 2.x, that there is no point in creating an integration. |
@Zhuinden Yes, I am using the |
You need to remove the NestedScrollView and whatever it's currently solving you have to most likely solve with item view types. |
I just published Compass which provides set of APIs to integrate Realm with Jetpack Paging 3. The API looks like this: val pagedPersons = RealmQuery { where<Person>() }.asPagingItems() Here It also provides a way to read only subset of data into memory with the overload: val pagedPersonNames = RealmQuery { where<Person>() }.asPagingItems { it.name } Example with Android ViewModel: class MyViewModel: ViewModel() {
val results = RealmQuery { where<Task>() }.asPagingItems().cachedIn(viewModelScope)
} It can support transforms, caching and seperators from Paging lib as described here. Any feedback appreciated. |
See https://medium.com/@Zhuinden/live-paged-lists-architecture-components-and-room-or-realm-268c9299a661
and
https://github.com/Zhuinden/realm-helpers/blob/4b83911b20304355e95870e51a1743bc141a36fd/realm-pagination-example/src/main/java/com/zhuinden/realmpaginationexample/data/dao/TaskDao.java#L25-L28
Although I'm sure the API can be nicer (not having to explicitly open/close, and while keep the notification could be moved to a background handler thread, but otherwise use
refresh()
in thedo { while
loop on theio()
scheduler of the computable live data.The text was updated successfully, but these errors were encountered: