mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Avoid iterating over records hash when not necessary
If the reflection scope is not flagged with distinct value, there is no need to iterate over the records, so we avoid that by doing the check before iterating rather than inside the iteration block.
This commit is contained in:
parent
1eee48144b
commit
492e6b57d4
1 changed files with 6 additions and 2 deletions
|
@ -5,9 +5,13 @@ module ActiveRecord
|
|||
include ThroughAssociation
|
||||
|
||||
def associated_records_by_owner
|
||||
super.each_value do |records|
|
||||
records.uniq! if reflection_scope.distinct_value
|
||||
records_by_owner = super
|
||||
|
||||
if reflection_scope.distinct_value
|
||||
records_by_owner.each_value { |records| records.uniq! }
|
||||
end
|
||||
|
||||
records_by_owner
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue