aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-09-20 11:50:14 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-09-20 11:50:14 -0700
commit7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b (patch)
tree41dbb8f4df552de5e8d3d83dfc5a723b97a17367 /activerecord/lib
parent51703256982ed2879b8b154917640b8bd8e05ae8 (diff)
downloadrails-7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b.tar.gz
rails-7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b.tar.bz2
rails-7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b.zip
generate fewer objects when grouping
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/associations/preloader.rb12
1 files changed, 7 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/associations/preloader.rb b/activerecord/lib/active_record/associations/preloader.rb
index d978a083b3..fd294051d4 100644
--- a/activerecord/lib/active_record/associations/preloader.rb
+++ b/activerecord/lib/active_record/associations/preloader.rb
@@ -134,11 +134,13 @@ module ActiveRecord
end
def grouped_records(association)
- Hash[
- records_by_reflection(association).map do |reflection, records|
- [reflection, records.group_by { |record| association_klass(reflection, record) }]
- end
- ]
+ reflection_records = records_by_reflection(association)
+
+ reflection_records.each_with_object({}) do |(reflection, records),h|
+ h[reflection] = records.group_by { |record|
+ association_klass(reflection, record)
+ }
+ end
end
def records_by_reflection(association)