1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Always use faster HomogeneousIn in array handler

This commit is contained in:
Ryuta Kamizono 2020-07-25 17:58:10 +09:00
parent de2520718f
commit a9336a67b0

View file

@ -20,23 +20,19 @@ module ActiveRecord
case values.length case values.length
when 0 then NullPredicate when 0 then NullPredicate
when 1 then predicate_builder.build(attribute, values.first) when 1 then predicate_builder.build(attribute, values.first)
else else Arel::Nodes::HomogeneousIn.new(values, attribute, :in)
if nils.empty? && ranges.empty?
return Arel::Nodes::HomogeneousIn.new(values, attribute, :in)
else
attribute.in values.map { |v|
predicate_builder.build_bind_attribute(attribute.name, v)
}
end
end end
unless nils.empty? unless nils.empty?
values_predicate = values_predicate.or(predicate_builder.build(attribute, nil)) values_predicate = values_predicate.or(attribute.eq(nil))
end end
array_predicates = ranges.map { |range| predicate_builder.build(attribute, range) } if ranges.empty?
array_predicates.unshift(values_predicate) values_predicate
array_predicates.inject(&:or) else
array_predicates = ranges.map! { |range| predicate_builder.build(attribute, range) }
array_predicates.inject(values_predicate, &:or)
end
end end
private private