未验证 提交 cd3c0fa3 编写于 作者: M Matthew Draper 提交者: GitHub

Merge pull request #28869 from eugeneius/query_cache_all_pools

Enable query cache on all connection pools
......@@ -26,16 +26,19 @@ def uncached(&block)
end
def self.run
caching_pool = ActiveRecord::Base.connection_pool
caching_was_enabled = caching_pool.query_cache_enabled
ActiveRecord::Base.connection_handler.connection_pool_list.map do |pool|
caching_was_enabled = pool.query_cache_enabled
caching_pool.enable_query_cache!
pool.enable_query_cache!
[caching_pool, caching_was_enabled]
[pool, caching_was_enabled]
end
end
def self.complete((caching_pool, caching_was_enabled))
caching_pool.disable_query_cache! unless caching_was_enabled
def self.complete(caching_pools)
caching_pools.each do |pool, caching_was_enabled|
pool.disable_query_cache! unless caching_was_enabled
end
ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
......
......@@ -452,6 +452,15 @@ def test_query_caching_is_local_to_the_current_thread
end
end
def test_query_cache_is_enabled_on_all_connection_pools
middleware {
ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
assert pool.query_cache_enabled
assert pool.connection.query_cache_enabled
end
}.call({})
end
private
def middleware(&app)
executor = Class.new(ActiveSupport::Executor)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册