提交 fbd1d306 编写于 作者: N Neeraj Singh 提交者: Aaron Patterson

Three performance improvements:

* for simple cases like User.last and User.order('name desc').last no need to perform Array#join operation.

* Instead of performing String#blank? do Array#empty?

* no need to create variable relation
上级 e3d6434d
......@@ -135,14 +135,13 @@ def extending(*modules, &block)
end
def reverse_order
order_clause = arel.order_clauses.join(', ')
relation = except(:order)
order_clause = arel.order_clauses
order = order_clause.blank? ?
order = order_clause.empty? ?
"#{@klass.table_name}.#{@klass.primary_key} DESC" :
reverse_sql_order(order_clause)
reverse_sql_order(order_clause).join(', ')
relation.order(Arel::SqlLiteral.new(order))
except(:order).order(Arel::SqlLiteral.new(order))
end
def arel
......@@ -283,15 +282,15 @@ def apply_modules(modules)
end
def reverse_sql_order(order_query)
order_query.split(',').each { |s|
order_query.join(', ').split(',').collect { |s|
if s.match(/\s(asc|ASC)$/)
s.gsub!(/\s(asc|ASC)$/, ' DESC')
s.gsub(/\s(asc|ASC)$/, ' DESC')
elsif s.match(/\s(desc|DESC)$/)
s.gsub!(/\s(desc|DESC)$/, ' ASC')
s.gsub(/\s(desc|DESC)$/, ' ASC')
else
s.concat(' DESC')
s + ' DESC'
end
}.join(',')
}
end
def array_of_strings?(o)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册