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

Merged
merged 1 commit into from Jul 7, 2011

Conversation

Projects
None yet
2 participants
@knapo
Contributor

knapo commented Jul 7, 2011

This caused that find_each may produce extra db call taking all the records from db, return array with all records, and was less efficient than ActiveRecord::Base#all. There is no sense to keep scope with this method, as it expects block and having further scopes after find_each is not possible.

eg. (notice last query)

ruby-1.9.2-p180 :016 > User.find_each{|u| }
  User Load (93.8ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` >= 0) ORDER BY `users`.`id` ASC LIMIT 1000
  User Load (175.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` > 1000) ORDER BY `users`.`id` ASC LIMIT 1000
  User Load (0.5ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` > 2000) ORDER BY `users`.`id` ASC LIMIT 1000
  User Load (308.2ms)  SELECT `users`.* FROM `users` 
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`.

spastorino added a commit that referenced this pull request Jul 7, 2011

Merge pull request #1997 from knapo/master
Make `ActiveRecord::Batches#find_each` to not return `self`.

@spastorino spastorino merged commit 63861e0 into rails:master Jul 7, 2011

@spastorino

This comment has been minimized.

Show comment Hide comment
@spastorino

spastorino Jul 7, 2011

Member

@knapo can you backport this to 3-1-stable and 3-0-stable ? thx.

Member

spastorino commented Jul 7, 2011

@knapo can you backport this to 3-1-stable and 3-0-stable ? thx.

@knapo

This comment has been minimized.

Show comment Hide comment
@knapo

knapo Jul 7, 2011

Contributor

@spastorino - here you go:
#2004
#2002

Contributor

knapo commented Jul 7, 2011

@spastorino - here you go:
#2004
#2002

@spastorino

This comment has been minimized.

Show comment Hide comment
@spastorino

spastorino Jul 7, 2011

Member

@knapo thank you very much!!!

Member

spastorino commented Jul 7, 2011

@knapo thank you very much!!!

spastorino added a commit that referenced this pull request Jul 7, 2011

spastorino added a commit that referenced this pull request Jul 7, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment