diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-08-30 23:05:14 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-08-30 23:05:14 +0100 |
commit | c30f6c270da5cd2ad7605ee9255f052e93609e30 (patch) | |
tree | 456a0cf70d2881a3f459b4da6c3ece3eb985e10d /railties | |
parent | 19d99971f77d3df0b4d1dbfef195559f631cf179 (diff) | |
download | rails-c30f6c270da5cd2ad7605ee9255f052e93609e30.tar.gz rails-c30f6c270da5cd2ad7605ee9255f052e93609e30.tar.bz2 rails-c30f6c270da5cd2ad7605ee9255f052e93609e30.zip |
User.each is a lie
Diffstat (limited to 'railties')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index b54b5c116b..178a5c50bf 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -159,14 +159,14 @@ The following may seem very straight forward at first: <ruby> # Very inefficient when users table has thousands of rows. -User.each do |user| +User.all.each do |user| NewsLetter.weekly_deliver(user) end </ruby> But if the total number of rows in the table is very large, the above approach may vary from being under performant to just plain impossible. -This is because +User.each+ makes Active Record fetch _the entire table_, build a model object per row, and keep the entire array in the memory. Sometimes that is just too many objects and demands too much memory. +This is because +User.all.each+ makes Active Record fetch _the entire table_, build a model object per row, and keep the entire array in the memory. Sometimes that is just too many objects and demands too much memory. h5. +find_each+ |