diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-07 12:13:47 -0300 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2013-04-07 12:14:53 -0300 |
commit | 492e6b57d43524dd6183fd8f33e4bdd7e8e8ceeb (patch) | |
tree | 3a25811f26a28b56c40d437c3009d52185d31cca /activerecord | |
parent | 1eee48144b43212ef1624525b44c7bb2cb845f43 (diff) | |
download | rails-492e6b57d43524dd6183fd8f33e4bdd7e8e8ceeb.tar.gz rails-492e6b57d43524dd6183fd8f33e4bdd7e8e8ceeb.tar.bz2 rails-492e6b57d43524dd6183fd8f33e4bdd7e8e8ceeb.zip |
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.
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/associations/preloader/has_many_through.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/has_many_through.rb b/activerecord/lib/active_record/associations/preloader/has_many_through.rb index 0dc551f100..157b627ad5 100644 --- a/activerecord/lib/active_record/associations/preloader/has_many_through.rb +++ b/activerecord/lib/active_record/associations/preloader/has_many_through.rb @@ -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 |