Browse files

eagerly build the bind map

  • Loading branch information...
1 parent 47037b6 commit 496204009eb3265a71d27c8a5513ca0dd803ea45 @tenderlove tenderlove committed Apr 11, 2014
Showing with 5 additions and 8 deletions.
  1. +5 −8 activerecord/lib/active_record/statement_cache.rb
View
13 activerecord/lib/active_record/statement_cache.rb
@@ -75,18 +75,19 @@ def bind(values)
end
def initialize(block = Proc.new)
- @mutex = Mutex.new
- @binds = nil
+ @mutex = Mutex.new
+ @binds = nil
@query_builder = nil
- @relation = block.call Params.new
+ @relation = block.call Params.new
+ @binds = BindMap.new @relation.bind_values
end
def execute(params)
rel = @relation
arel = rel.arel
klass = rel.klass
- bind_map = binds rel
+ bind_map = @binds
bind_values = bind_map.bind params
builder = query_builder klass.connection, arel
@@ -97,10 +98,6 @@ def execute(params)
alias :call :execute
private
- def binds(rel)
- @binds || @mutex.synchronize { @binds ||= BindMap.new rel.bind_values }
- end
-
def query_builder(connection, arel)
@query_builder || @mutex.synchronize {
@query_builder ||= connection.cacheable_query(arel)

0 comments on commit 4962040

Please sign in to comment.