mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
reducing function calls and using faster methods for testing
This commit is contained in:
parent
87a28e34ae
commit
d1c53a9ad2
2 changed files with 10 additions and 16 deletions
|
@ -99,7 +99,7 @@ module ActiveRecord
|
|||
if block_given?
|
||||
to_a.many? { |*block_args| yield(*block_args) }
|
||||
else
|
||||
@limit_value.present? ? to_a.many? : size > 1
|
||||
@limit_value ? to_a.many? : size > 1
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -316,12 +316,12 @@ module ActiveRecord
|
|||
|
||||
def scope_for_create
|
||||
@scope_for_create ||= begin
|
||||
@create_with_value || @where_values.inject({}) do |hash, where|
|
||||
if where.is_a?(Arel::Predicates::Equality)
|
||||
hash[where.operand1.name] = where.operand2.respond_to?(:value) ? where.operand2.value : where.operand2
|
||||
end
|
||||
hash
|
||||
end
|
||||
@create_with_value || Hash[
|
||||
@where_values.grep(Arel::Predicates::Equality).map { |where|
|
||||
[where.operand1.name,
|
||||
where.operand2.respond_to?(:value) ?
|
||||
where.operand2.value : where.operand2]
|
||||
}]
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ module ActiveRecord
|
|||
def build_arel
|
||||
arel = table
|
||||
|
||||
arel = build_joins(arel, @joins_values) if @joins_values.present?
|
||||
arel = build_joins(arel, @joins_values) unless @joins_values.empty?
|
||||
|
||||
@where_values.uniq.each do |where|
|
||||
next if where.blank?
|
||||
|
@ -145,7 +145,7 @@ module ActiveRecord
|
|||
|
||||
arel = arel.having(*@having_values.uniq.select{|h| h.present?}) if @having_values.present?
|
||||
|
||||
arel = arel.take(@limit_value) if @limit_value.present?
|
||||
arel = arel.take(@limit_value) if @limit_value
|
||||
arel = arel.skip(@offset_value) if @offset_value.present?
|
||||
|
||||
arel = arel.group(*@group_values.uniq.select{|g| g.present?}) if @group_values.present?
|
||||
|
@ -155,13 +155,7 @@ module ActiveRecord
|
|||
arel = build_select(arel, @select_values.uniq)
|
||||
|
||||
arel = arel.from(@from_value) if @from_value.present?
|
||||
|
||||
case @lock_value
|
||||
when TrueClass
|
||||
arel = arel.lock
|
||||
when String
|
||||
arel = arel.lock(@lock_value)
|
||||
end if @lock_value.present?
|
||||
arel = arel.lock(@lock_value) if @lock_value
|
||||
|
||||
arel
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue