未验证 提交 e1203433 编写于 作者: R Rafael França 提交者: GitHub

Merge pull request #32414 from bogdan/query-cache-optimization

Optimize the code inside AR::QueryCache middleware
......@@ -26,19 +26,12 @@ def uncached(&block)
end
def self.run
ActiveRecord::Base.connection_handler.connection_pool_list.map do |pool|
caching_was_enabled = pool.query_cache_enabled
pool.enable_query_cache!
[pool, caching_was_enabled]
end
ActiveRecord::Base.connection_handler.connection_pool_list.
reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! }
end
def self.complete(caching_pools)
caching_pools.each do |pool, caching_was_enabled|
pool.disable_query_cache! unless caching_was_enabled
end
def self.complete(pools)
pools.each { |pool| pool.disable_query_cache! }
ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
......
......@@ -441,8 +441,9 @@ def test_query_cache_is_enabled_on_connections_established_after_middleware_runs
assert_not ActiveRecord::Base.connection_handler.active_connections? # sanity check
middleware {
assert ActiveRecord::Base.connection.query_cache_enabled, "QueryCache did not get lazily enabled"
assert_predicate ActiveRecord::Base.connection, :query_cache_enabled
}.call({})
assert_not_predicate ActiveRecord::Base.connection, :query_cache_enabled
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册