Rails ActiveRecord::Batches aka find in batches

Rails find_in_batches

Person.find_in_batches.with_index do |group, batch|
  puts "Processing group ##{batch}"
  group.each(&:recover_from_last_night!)
end

Rails in_batches

Person.in_batches.each do |relation|
    relation.update_all('age = age + 1')
    relation.where('age > 21').update_all(should_party: true)
    relation.where('age <= 21').delete_all
end
Back