10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/superstore/scope/batches.rb', line 10
def find_in_batches(options = {})
batch_size = options.delete(:batch_size) || 1000
start_key = nil
scope = limit(batch_size + 1).order(:id)
records = scope.to_a
while records.any?
if records.size > batch_size
next_record = records.pop
else
next_record = nil
end
yield records
break if next_record.nil?
records = scope.where("#{adapter.primary_key_column} >= '#{next_record.id}'").to_a
end
end
|