aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/query_cache.rb
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2016-11-10 14:18:40 -0500
committerGitHub <noreply@github.com>2016-11-10 14:18:40 -0500
commitcac3be6341f95c9a347d62173a4a130d1e42141b (patch)
tree0e24a0271cbe5ab2e50615685cb8c51093705a50 /activerecord/lib/active_record/query_cache.rb
parentc58083584c3a7a2e29f609760547e10e46d56a33 (diff)
parent3c785bdceed4bdf67708197aa687ced6728d77f3 (diff)
downloadrails-cac3be6341f95c9a347d62173a4a130d1e42141b.tar.gz
rails-cac3be6341f95c9a347d62173a4a130d1e42141b.tar.bz2
rails-cac3be6341f95c9a347d62173a4a130d1e42141b.zip
Merge pull request #26978 from matthewd/query-cache-pool
Configure query caching (per thread) on the connection pool
Diffstat (limited to 'activerecord/lib/active_record/query_cache.rb')
-rw-r--r--activerecord/lib/active_record/query_cache.rb15
1 files changed, 11 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb
index 23dae825c2..ec246e97bc 100644
--- a/activerecord/lib/active_record/query_cache.rb
+++ b/activerecord/lib/active_record/query_cache.rb
@@ -24,12 +24,19 @@ module ActiveRecord
end
def self.run
- ActiveRecord::Base.connection.enable_query_cache!
+ caching_pool = ActiveRecord::Base.connection_pool
+ caching_was_enabled = caching_pool.query_cache_enabled
+
+ caching_pool.enable_query_cache!
+
+ [caching_pool, caching_was_enabled]
end
- def self.complete(_)
- unless ActiveRecord::Base.connected? && ActiveRecord::Base.connection.transaction_open?
- ActiveRecord::Base.clear_active_connections!
+ def self.complete((caching_pool, caching_was_enabled))
+ caching_pool.disable_query_cache! unless caching_was_enabled
+
+ ActiveRecord::Base.connection_handler.connection_pool_list.each do |pool|
+ pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
end
end