Closed msalvadores closed 7 years ago
ActiveModel has a decent api for this:
User.find_each(:start => 2000, :batch_size => 5000) do |user|
# do something with `user`
end
There's a good one for iterating over arrays of responses too:
# Give add_invoices an array of 1000 invoices at a time
Invoice.find_in_batches(:include => :invoice_lines) do |invoices|
# invoices is an array with 1000 invoice objects
export.add_invoices(invoices)
end
:+1: I like it.
@palexander how Active Model does to know the number of pages in find_in_batches
?
It doesn't know the number of pages, you just keep iterating until all records are found. I guess this isn't really pagination, more a convenient way to work with groups of results when getting back Invoice.all would be too much data.
Here's more info: http://apidock.com/rails/ActiveRecord/Batches/ClassMethods/find_in_batches
As discussed we do not worry about this now. We only need pagination for mappings and classes (in the ontology linked data API). It can wait.
Offset limit and some kind of ordering when retrieving Goo objects.
This should be done accordingly to the issue about changing the API for search