Permalink
Browse files

Make `ActiveRecord::Batches#find_each` to not return `self`.

This caused that `find_each` was producing extra db call taking all the records from db, and was less efficient than `ActiveRecord::Base#all`.
  • Loading branch information...
knapo committed Jul 7, 2011
1 parent 9e4d156 commit e2d90bf8f5b9124aecbe2ebb4776314a34f7321d
Showing with 7 additions and 2 deletions.
  1. +0 −2 activerecord/lib/active_record/relation/batches.rb
  2. +7 −0 activerecord/test/cases/batches_test.rb
@@ -20,8 +20,6 @@ def find_each(options = {})
find_in_batches(options) do |records|
records.each { |record| yield record }
end
-
- self
end
# Yields each batch of records that was found by the find +options+ as
@@ -17,6 +17,13 @@ def test_each_should_excecute_one_query_per_batch
end
end
+ def test_each_should_not_return_query_chain_and_execcute_only_one_query
+ assert_queries(1) do
+ result = Post.find_each(:batch_size => 100000){ }
+ assert_nil result
+ end
+ end
+
def test_each_should_raise_if_select_is_set_without_id
assert_raise(RuntimeError) do
Post.find_each(:select => :title, :batch_size => 1) { |post| post }

0 comments on commit e2d90bf

Please sign in to comment.