Skip to content
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

RBQFetchRequest add fetchLimit support. #5

Open
ghost opened this issue Apr 7, 2015 · 10 comments
Open

RBQFetchRequest add fetchLimit support. #5

ghost opened this issue Apr 7, 2015 · 10 comments

Comments

@ghost
Copy link

ghost commented Apr 7, 2015

Sometimes may need limit fetched count like NSFetchRequest, can you add fetchlimit to RBQFetchRequest? Thanks.

@bigfish24
Copy link
Contributor

This won't be possible right now because Realm doesn't make available limiting through their query API (I believe the TightDB core offers this though they just haven't added it to the wrapper). So the only way would be to loop through the RLMResults and copy the first X into a NSArray for example. You can do this manually since it wouldn't make sense to setup RBQFetchrequest to work this way, because if you don't need a limit this isn't very performant. Makes sense?

@bigfish24
Copy link
Contributor

FYI: here's relevant Realm issue regarding adding a limit to RLMResults (which RBQFetchRequest uses) realm/realm-swift#1448

@ghost
Copy link
Author

ghost commented Apr 8, 2015

Thanks for your reply.I'll try other way to solve my problem, wish realm can update soon.

@bigfish24
Copy link
Contributor

No problem, sorry couldn't be of more help. The one thing I should note is that at least in terms of memory management it isn't necessary to limit the results since RLMResults lazy loads the objects. So if you simply used the RLMResults directly as a UITableView datasource (instead of the FRC since internally it has its own cache complicating my point), then when the user scrolls and a cell is created, only then is the data accessed from the object at that specific index in the RLMResults. This prevents the need to limit the results or do any paging.

@ghost
Copy link
Author

ghost commented Apr 8, 2015

Yeah, I limit the count just for paging logic.

@bigfish24
Copy link
Contributor

Ah, well in that case if you are simply trying to achieve a UI effect, you don't need to actually page the RLMResults to improve performance. Just limit the rows on the UITableview manually (i.e. don't match the rows in UITableview datasource to the RLMResults count), and then increase this by X until you reach the results count in response to the user requesting to see more.

@bigfish24
Copy link
Contributor

The only tricky thing with this would be if you plan to use RBQFetchedResultsController to manage changes to the UITableView, you would have to catch any delegate calls that reference a index path that is not currently visible and not pass that change to the UITableView or you will get an assertion failure.

@ghost
Copy link
Author

ghost commented Apr 8, 2015

That's the problem so I tried other way: every model I have a flag and I reset all model's flag to false after refresh then set the new fetched model's flag to true then addOrUpdate.Througn this way i can limit the count.

@bigfish24
Copy link
Contributor

Ah that makes sense, glad you figured out a fix for the time being.

@andreaferrando
Copy link

Great thanks! I noticed this post is a bit old, are there any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants