Permalink
Browse files

generate fewer objects when grouping

  • Loading branch information...
1 parent 5170325 commit 7ad26e8a45c2c04a5b9adfa9fb4979d906771f5b @tenderlove tenderlove committed Sep 20, 2013
Showing with 7 additions and 5 deletions.
  1. +7 −5 activerecord/lib/active_record/associations/preloader.rb
View
12 activerecord/lib/active_record/associations/preloader.rb
@@ -134,11 +134,13 @@ def preload_one(association)
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)

0 comments on commit 7ad26e8

Please sign in to comment.