Skip to content

Commit

Permalink
generate fewer objects when grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Sep 20, 2013
1 parent 5170325 commit 7ad26e8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions activerecord/lib/active_record/associations/preloader.rb
Expand Up @@ -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)
Expand Down

0 comments on commit 7ad26e8

Please sign in to comment.