diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 16:47:20 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-09 16:47:20 -0700 |
commit | 6388b4b15383c93c647c4b3732df2cb8940444bf (patch) | |
tree | c000b9678e0ae2ff698787026325846e401798bb | |
parent | b1ba76840d5ea7920bd193f8f6803192014e0f45 (diff) | |
download | rails-6388b4b15383c93c647c4b3732df2cb8940444bf.tar.gz rails-6388b4b15383c93c647c4b3732df2cb8940444bf.tar.bz2 rails-6388b4b15383c93c647c4b3732df2cb8940444bf.zip |
speed up parameter substitution
store the offsets of the bind values, then only index to bind value
locations before joining the array
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index c89dd48642..5811e4ba6b 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -27,8 +27,18 @@ module ActiveRecord end class PartialQuery < Query + def initialize values + @values = values + @indexes = values.each_with_index.find_all { |thing,i| + Arel::Nodes::BindParam === thing + }.map(&:last) + end + def sql_for(binds, connection) - @sql.compile binds, connection + val = @values.dup + binds = binds.dup + @indexes.each { |i| val[i] = connection.quote(*binds.shift.reverse) } + val.join end end @@ -37,7 +47,7 @@ module ActiveRecord end def self.partial_query(visitor, ast, collector) - collected = visitor.accept(ast, collector) + collected = visitor.accept(ast, collector).value PartialQuery.new collected end |