diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-19 20:53:53 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-19 20:53:53 -0700 |
commit | 8c511c0b3ce02df75e8c089cb6cfd4e0a958a0cf (patch) | |
tree | 178db63dcaaa40649ca2d0e74f347da84fc25102 /activerecord | |
parent | 4726a181c4c817e64d656b4b228030e468eeb48f (diff) | |
download | rails-8c511c0b3ce02df75e8c089cb6cfd4e0a958a0cf.tar.gz rails-8c511c0b3ce02df75e8c089cb6cfd4e0a958a0cf.tar.bz2 rails-8c511c0b3ce02df75e8c089cb6cfd4e0a958a0cf.zip |
swap out some n^2 for some n
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index e644670019..b8b0898cc8 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -26,15 +26,21 @@ module ActiveRecord merged_relation = merged_relation.joins(r.joins_values) - merged_wheres = @where_values.dup + merged_wheres = @where_values.dup + r.where_values - r.where_values.each do |w| - if w.respond_to?(:operator) && w.operator == :== - merged_wheres = merged_wheres.reject {|p| p.respond_to?(:operator) && p.operator == :== && p.operand1.name == w.operand1.name } - end + equality_wheres = merged_wheres.find_all { |w| + w.respond_to?(:operator) && w.operator == :== + } - merged_wheres << w - end + equality_wheres_by_operand = equality_wheres.group_by { |eq| + eq.left.name + } + + duplicates = equality_wheres_by_operand.map { |name, list| + list[0...-1] + }.flatten + + merged_wheres -= duplicates merged_relation.where_values = merged_wheres |