diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2010-01-21 17:48:53 +0530 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2010-01-21 17:52:09 +0530 |
commit | da142cd86584d56299470ee4dd6f90be7127b477 (patch) | |
tree | aa20ecac64534a6b440b0978da3ec9768229377b /activerecord/lib/active_record/relation/query_methods.rb | |
parent | 378464a2e47bb849f3351cb8c87366554b7ce74d (diff) | |
download | rails-da142cd86584d56299470ee4dd6f90be7127b477.tar.gz rails-da142cd86584d56299470ee4dd6f90be7127b477.tar.bz2 rails-da142cd86584d56299470ee4dd6f90be7127b477.zip |
Supplying Arel::SqlLiteral is much faster
Diffstat (limited to 'activerecord/lib/active_record/relation/query_methods.rb')
-rw-r--r-- | activerecord/lib/active_record/relation/query_methods.rb | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/relation/query_methods.rb b/activerecord/lib/active_record/relation/query_methods.rb index d0689cd93e..ce3e4e8eed 100644 --- a/activerecord/lib/active_record/relation/query_methods.rb +++ b/activerecord/lib/active_record/relation/query_methods.rb @@ -119,8 +119,16 @@ module ActiveRecord end end - @where_values.uniq.each do |w| - arel = w.is_a?(String) ? arel.where(w) : arel.where(*w) + @where_values.uniq.each do |where| + next if where.blank? + + case where + when Arel::SqlLiteral + arel = arel.where(where) + else + sql = where.is_a?(String) ? where : where.to_sql + arel = arel.where(Arel::SqlLiteral.new("(#{sql})")) + end end @having_values.uniq.each do |h| @@ -135,7 +143,7 @@ module ActiveRecord end @order_values.uniq.each do |o| - arel = arel.order(o) if o.present? + arel = arel.order(Arel::SqlLiteral.new(o.to_s)) if o.present? end selects = @select_values.uniq @@ -169,8 +177,7 @@ module ActiveRecord builder = PredicateBuilder.new(table.engine) conditions = if [String, Array].include?(args.first.class) - sql = @klass.send(:sanitize_sql, args.size > 1 ? args : args.first) - Arel::SqlLiteral.new("(#{sql})") if sql.present? + @klass.send(:sanitize_sql, args.size > 1 ? args : args.first) elsif args.first.is_a?(Hash) attributes = @klass.send(:expand_hash_conditions_for_aggregates, args.first) builder.build_from_hash(attributes, table) |