diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-10 17:20:22 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-04-10 17:20:22 -0700 |
commit | 249fd686fb86c89463d791f44114fd829cb05bd2 (patch) | |
tree | 310fbf4d9827beb4b16072a437ca7c375022a0b8 /activerecord/lib/active_record | |
parent | 2d3969c82fd8aa57186c263afd4b2d93eb6ba5d3 (diff) | |
download | rails-249fd686fb86c89463d791f44114fd829cb05bd2.tar.gz rails-249fd686fb86c89463d791f44114fd829cb05bd2.tar.bz2 rails-249fd686fb86c89463d791f44114fd829cb05bd2.zip |
remove intelligence from StatementCache#initialize
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/core.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/statement_cache.rb | 20 |
2 files changed, 13 insertions, 11 deletions
diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index 4b77e0e01a..1b7f579aa3 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -135,7 +135,7 @@ module ActiveRecord key = primary_key s = find_by_statement_cache[key] || find_by_statement_cache.synchronize { - find_by_statement_cache[key] ||= StatementCache.new { |params| + find_by_statement_cache[key] ||= StatementCache.create { |params| where(key => params[key]).limit(1) } } @@ -159,7 +159,7 @@ module ActiveRecord klass = self s = find_by_statement_cache[key] || find_by_statement_cache.synchronize { - find_by_statement_cache[key] ||= StatementCache.new { |params| + find_by_statement_cache[key] ||= StatementCache.create { |params| wheres = key.each_with_object({}) { |param,o| o[param] = params[param] } diff --git a/activerecord/lib/active_record/statement_cache.rb b/activerecord/lib/active_record/statement_cache.rb index c70d2f2d11..fbba95d78f 100644 --- a/activerecord/lib/active_record/statement_cache.rb +++ b/activerecord/lib/active_record/statement_cache.rb @@ -76,11 +76,18 @@ module ActiveRecord attr_reader :bind_map, :query_builder - def initialize(block = Proc.new) - relation = block.call Params.new - @bind_map = BindMap.new relation.bind_values + def self.create(block = Proc.new) + relation = block.call Params.new + bind_map = BindMap.new relation.bind_values klass = relation.klass - @query_builder = make_query_builder klass.connection, relation.arel + connection = klass.connection + query_builder = connection.cacheable_query relation.arel + new query_builder, bind_map + end + + def initialize(query_builder, bind_map) + @query_builder = query_builder + @bind_map = bind_map end def execute(params, klass, connection) @@ -91,10 +98,5 @@ module ActiveRecord klass.find_by_sql sql, bind_values end alias :call :execute - - private - def make_query_builder(connection, arel) - connection.cacheable_query(arel) - end end end |