Skip to content

Commit bcc6c4b

Browse files
authored
Merge pull request rails#41256 from eileencodes/revert-qc-changes
Revert qc changes
2 parents 3921f24 + 7f2f870 commit bcc6c4b

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

activerecord/lib/active_record/query_cache.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,30 @@ def uncached(&block)
2626
end
2727

2828
def self.run
29+
pools = []
30+
2931
if ActiveRecord::Base.legacy_connection_handling
30-
ActiveRecord::Base.connection_handlers.each_value do |handler|
31-
handler.connection_pool_list.each(&:enable_query_cache!)
32+
ActiveRecord::Base.connection_handlers.each do |key, handler|
33+
pools.concat(handler.connection_pool_list.reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! })
3234
end
3335
else
34-
ActiveRecord::Base.connection_handler.all_connection_pools.each(&:enable_query_cache!)
36+
pools.concat(ActiveRecord::Base.connection_handler.all_connection_pools.reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! })
3537
end
38+
39+
pools
3640
end
3741

38-
def self.complete(_)
42+
def self.complete(pools)
43+
pools.each { |pool| pool.disable_query_cache! }
44+
3945
if ActiveRecord::Base.legacy_connection_handling
40-
ActiveRecord::Base.connection_handlers.each_value do |handler|
46+
ActiveRecord::Base.connection_handlers.each do |_, handler|
4147
handler.connection_pool_list.each do |pool|
42-
pool.disable_query_cache!
4348
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
4449
end
4550
end
4651
else
4752
ActiveRecord::Base.connection_handler.all_connection_pools.each do |pool|
48-
pool.disable_query_cache!
4953
pool.release_connection if pool.active_connection? && !pool.connection.transaction_open?
5054
end
5155
end

0 commit comments

Comments
 (0)