Skip to content
This repository
Browse code

make add_order a tad faster

git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/1-2-pre-release@5453 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit 84668af33067b9d24252f11a5580769d7f6eadf3 1 parent 013004b
Jamis Buck jamis authored
2  activerecord/CHANGELOG
... ... @@ -1,5 +1,7 @@
1 1 *SVN*
2 2
  3 +* make add_order a tad faster. #6567 [Stefan Kaes]
  4 +
3 5 * Find with :include respects scoped :order. #5850
4 6
5 7 * Dynamically generate reader methods for serialized attributes. #6362 [Stefan Kaes]
10 activerecord/lib/active_record/base.rb
@@ -1096,7 +1096,7 @@ def construct_finder_sql(options)
1096 1096
1097 1097 sql << " GROUP BY #{options[:group]} " if options[:group]
1098 1098
1099   - add_order!(sql, options[:order])
  1099 + add_order!(sql, options[:order], scope)
1100 1100 add_limit!(sql, options, scope)
1101 1101 add_lock!(sql, options, scope)
1102 1102
@@ -1120,12 +1120,14 @@ def safe_to_array(o)
1120 1120 end
1121 1121 end
1122 1122
1123   - def add_order!(sql, order)
  1123 + def add_order!(sql, order, scope = :auto)
  1124 + scope = scope(:find) if :auto == scope
  1125 + scoped_order = scope[:order] if scope
1124 1126 if order
1125 1127 sql << " ORDER BY #{order}"
1126   - sql << ", #{scope(:find, :order)}" if scoped?(:find, :order)
  1128 + sql << ", #{scoped_order}" if scoped_order
1127 1129 else
1128   - sql << " ORDER BY #{scope(:find, :order)}" if scoped?(:find, :order)
  1130 + sql << " ORDER BY #{scoped_order}" if scoped_order
1129 1131 end
1130 1132 end
1131 1133

0 comments on commit 84668af

Please sign in to comment.
Something went wrong with that request. Please try again.