1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

speeding up query cache

This commit is contained in:
Aaron Patterson 2010-10-27 14:23:01 -07:00
parent 7104122cc3
commit 9ce0211806
2 changed files with 4 additions and 5 deletions

View file

@ -59,14 +59,13 @@ module ActiveRecord
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

View file

@ -41,7 +41,7 @@ module ActiveRecord
@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