swap out some n^2 for some n

This commit is contained in:
Aaron Patterson
2010-10-19 20:53:53 -07:00
parent 4726a181c4
commit 8c511c0b3c

View File

@@ -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