Module: ActiveRecord::Stream::ClassMethods
- Defined in:
- lib/activerecord/stream.rb
Instance Method Summary collapse
Instance Method Details
#stream(options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/activerecord/stream.rb', line 12 def stream(={}) offset = [:start] || 0 batch_size = [:batch_size] || 500 scope = respond_to?(:scoped) ? scoped : all Enumerator.new do |yielder| loop do current_batch = load_batch(scope, batch_size, offset) current_batch.each{|r| yielder << r} break if current_batch.length < batch_size offset += batch_size end end end |