diff options
author | Bogdan Gusiev <agresso@gmail.com> | 2018-03-31 18:29:08 +0300 |
---|---|---|
committer | Bogdan Gusiev <agresso@gmail.com> | 2018-04-04 17:49:06 +0300 |
commit | fb75c891ac7fe7331a9a967a96c674ed35eabdcf (patch) | |
tree | 5683c189e08dedcf938c9b808593a26e30d23835 | |
parent | f339b098b20c7f6675d375cfa29828a911fe1b53 (diff) | |
download | rails-fb75c891ac7fe7331a9a967a96c674ed35eabdcf.tar.gz rails-fb75c891ac7fe7331a9a967a96c674ed35eabdcf.tar.bz2 rails-fb75c891ac7fe7331a9a967a96c674ed35eabdcf.zip |
Optimize the code inside AR::QueryCache middleware
-rw-r--r-- | activerecord/lib/active_record/query_cache.rb | 15 | ||||
-rw-r--r-- | activerecord/test/cases/query_cache_test.rb | 3 |
2 files changed, 6 insertions, 12 deletions
diff --git a/activerecord/lib/active_record/query_cache.rb b/activerecord/lib/active_record/query_cache.rb index c8e340712d..28194c7c46 100644 --- a/activerecord/lib/active_record/query_cache.rb +++ b/activerecord/lib/active_record/query_cache.rb @@ -26,19 +26,12 @@ module ActiveRecord 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? diff --git a/activerecord/test/cases/query_cache_test.rb b/activerecord/test/cases/query_cache_test.rb index d635a47c0e..07be046fb7 100644 --- a/activerecord/test/cases/query_cache_test.rb +++ b/activerecord/test/cases/query_cache_test.rb @@ -441,8 +441,9 @@ class QueryCacheTest < ActiveRecord::TestCase 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 |