提交 9ce02118 编写于 作者: A Aaron Patterson

speeding up query cache

上级 7104122c
...@@ -59,14 +59,13 @@ def select_all(sql, name = nil, binds = []) ...@@ -59,14 +59,13 @@ def select_all(sql, name = nil, binds = [])
private private
def cache_sql(sql, binds) def cache_sql(sql, binds)
key = [sql, binds]
result = result =
if @query_cache.has_key?(key) if @query_cache[sql].key?(binds)
ActiveSupport::Notifications.instrument("sql.active_record", ActiveSupport::Notifications.instrument("sql.active_record",
:sql => sql, :name => "CACHE", :connection_id => self.object_id) :sql => sql, :name => "CACHE", :connection_id => self.object_id)
@query_cache[key] @query_cache[sql][binds]
else else
@query_cache[key] = yield @query_cache[sql][binds] = yield
end end
if Array === result if Array === result
......
...@@ -41,7 +41,7 @@ def initialize(connection, logger = nil) #:nodoc: ...@@ -41,7 +41,7 @@ def initialize(connection, logger = nil) #:nodoc:
@active = nil @active = nil
@connection, @logger = connection, logger @connection, @logger = connection, logger
@query_cache_enabled = false @query_cache_enabled = false
@query_cache = {} @query_cache = Hash.new { |h,sql| h[sql] = {} }
@instrumenter = ActiveSupport::Notifications.instrumenter @instrumenter = ActiveSupport::Notifications.instrumenter
end end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册