aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-10-20 08:41:18 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-10-20 08:41:25 -0700
commitdbc5d2694f0c77ca9de43306602969fdd3dbd20e (patch)
tree8cf3232736cafe20aa4bec07176013e06c909478 /activerecord/lib/active_record
parentd3d724bb8809906ebae3abbd2c4a11c8a4aec268 (diff)
downloadrails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.tar.gz
rails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.tar.bz2
rails-dbc5d2694f0c77ca9de43306602969fdd3dbd20e.zip
reduce duplicate where removal to one loop
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/spawn_methods.rb28
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