Sha256: e908c11ae0e2028b58bf8d1f357433b805f52ac91412525720c0ce24e753a7ae
Contents?: true
Size: 763 Bytes
Versions: 16
Compression:
Stored size: 763 Bytes
Contents
module Superstore class Scope module Batches def find_each(options = {}) find_in_batches(options) do |records| records.each { |record| yield record } end end 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 end end end
Version data entries
16 entries across 16 versions & 1 rubygems