I checked dm-chunked_query as @MichaelKohl suggested, but I couldn’t get it to work as I expected, it will get the whole collection (I expect it to use OFFSET + LIMIT). So I wrote my own extension, it is quite simple, hope this helps:
class DataMapper::Collection def batch(n) Enumerator.new do |y| offset = 0 loop do records = slice(offset, n) break if records.empty? records.each { |record| y.yield(record) } offset += records.size end end end end
source share