aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-09-28 14:32:59 -0400
committerAaron Patterson <aaron.patterson@gmail.com>2010-09-28 15:52:26 -0700
commit3f16103daf330a067454dd2ae324d8d238ac5ba3 (patch)
tree09ab264bf0f30b5bed3b4d412ca9d8b693489cd4 /activerecord/lib
parent9b89a436e59bfe50ef6dfd85bd12311f326d7140 (diff)
downloadrails-3f16103daf330a067454dd2ae324d8d238ac5ba3.tar.gz
rails-3f16103daf330a067454dd2ae324d8d238ac5ba3.tar.bz2
rails-3f16103daf330a067454dd2ae324d8d238ac5ba3.zip
performance improvement based on discussion at http://github.com/rails/rails/commit/fbd1d306b95cc2efb6422e12d26d5818a3a42343
Credit goes to all the participants in the discussion
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/query_methods.rb12
1 files changed, 3 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb
index b25388c0e8..e2b1330c24 100644
--- a/activerecord/lib/active_record/relation/query_methods.rb
+++ b/activerecord/lib/active_record/relation/query_methods.rb
@@ -280,15 +280,9 @@ module ActiveRecord
end
def reverse_sql_order(order_query)
- order_query.join(', ').split(',').collect { |s|
- if s.match(/\s(asc|ASC)$/)
- s.gsub(/\s(asc|ASC)$/, ' DESC')
- elsif s.match(/\s(desc|DESC)$/)
- s.gsub(/\s(desc|DESC)$/, ' ASC')
- else
- s + ' DESC'
- end
- }
+ order_query.join(', ').split(',').collect do |s|
+ s.gsub!(/\sasc\Z/i, ' DESC') || s.gsub!(/\sdesc\Z/i, ' ASC') || s.concat(' DESC')
+ end
end
def array_of_strings?(o)