diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-20 08:41:18 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2010-10-20 08:41:25 -0700 |
commit | dbc5d2694f0c77ca9de43306602969fdd3dbd20e (patch) | |
tree | 8cf3232736cafe20aa4bec07176013e06c909478 /activerecord | |
parent | d3d724bb8809906ebae3abbd2c4a11c8a4aec268 (diff) | |
download | rails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.tar.gz rails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.tar.bz2 rails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.zip |
reduce duplicate where removal to one loop
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/relation/spawn_methods.rb | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/activerecord/lib/active_record/relation/spawn_methods.rb b/activerecord/lib/active_record/relation/spawn_methods.rb index b8b0898cc8..648a02f1cc 100644 --- a/activerecord/lib/active_record/relation/spawn_methods.rb +++ b/activerecord/lib/active_record/relation/spawn_methods.rb @@ -26,21 +26,19 @@ module ActiveRecord merged_relation = merged_relation.joins(r.joins_values) - merged_wheres = @where_values.dup + r.where_values - - equality_wheres = merged_wheres.find_all { |w| - w.respond_to?(:operator) && w.operator == :== - } - - 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_wheres = @where_values + r.where_values + + # Remove duplicates, last one wins. + seen = {} + merged_wheres = merged_wheres.reverse.reject { |w| + nuke = false + if w.respond_to?(:operator) && w.operator == :== + name = w.left.name + nuke = seen[name] + seen[name] = true + end + nuke + }.reverse merged_relation.where_values = merged_wheres |