mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Fixed Ruby 1.8 performance regression for Nodes::In and Nodes::NotIn queries with very wide ranges that was caused by using Range#min and Range#max rather than Range#begin and Range#end. Ruby 1.8 uses Enumerable#min and Enumerable#max in Ranges, which calls to_a internally. It is not necessary to enumerate the range in order to construct the predicates. At the same time, an off-by-one error (failing test) with exclusive-end Ranges in Nodes::NotIn queries was fixed.
This commit is contained in:
parent
35f25f643c
commit
9244e2ddbd
1 changed files with 7 additions and 7 deletions
|
@ -30,11 +30,11 @@ module Arel
|
|||
Nodes::In.new self, other.to_a.map { |x| x.id }
|
||||
when Range
|
||||
if other.exclude_end?
|
||||
left = Nodes::GreaterThanOrEqual.new(self, other.min)
|
||||
right = Nodes::LessThan.new(self, other.max + 1)
|
||||
left = Nodes::GreaterThanOrEqual.new(self, other.begin)
|
||||
right = Nodes::LessThan.new(self, other.end)
|
||||
Nodes::And.new left, right
|
||||
else
|
||||
Nodes::Between.new(self, Nodes::And.new(other.min, other.max))
|
||||
Nodes::Between.new(self, Nodes::And.new(other.begin, other.end))
|
||||
end
|
||||
else
|
||||
Nodes::In.new self, other
|
||||
|
@ -55,12 +55,12 @@ module Arel
|
|||
Nodes::NotIn.new self, other.to_a.map { |x| x.id }
|
||||
when Range
|
||||
if other.exclude_end?
|
||||
left = Nodes::LessThan.new(self, other.min)
|
||||
right = Nodes::GreaterThanOrEqual.new(self, other.max)
|
||||
left = Nodes::LessThan.new(self, other.begin)
|
||||
right = Nodes::GreaterThanOrEqual.new(self, other.end)
|
||||
Nodes::Or.new left, right
|
||||
else
|
||||
left = Nodes::LessThan.new(self, other.min)
|
||||
right = Nodes::GreaterThan.new(self, other.max)
|
||||
left = Nodes::LessThan.new(self, other.begin)
|
||||
right = Nodes::GreaterThan.new(self, other.end)
|
||||
Nodes::Or.new left, right
|
||||
end
|
||||
else
|
||||
|
|
Loading…
Reference in a new issue