Skip to content

Commit

Permalink
eagerly build the relation object
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Apr 10, 2014
1 parent 90c9a09 commit 47037b6
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions activerecord/lib/active_record/statement_cache.rb
Expand Up @@ -76,15 +76,13 @@ def bind(values)

def initialize(block = Proc.new)
@mutex = Mutex.new
@relation = nil
@binds = nil
@block = block
@query_builder = nil
@params = Params.new
@relation = block.call Params.new
end

def execute(params)
rel = relation @params
rel = @relation

arel = rel.arel
klass = rel.klass
Expand All @@ -108,9 +106,5 @@ def query_builder(connection, arel)
@query_builder ||= connection.cacheable_query(arel)
}
end

def relation(values)
@relation || @mutex.synchronize { @relation ||= @block.call(values) }
end
end
end

0 comments on commit 47037b6

Please sign in to comment.