Skip to content

Commit

Permalink
Revert "Merge pull request #53484 from zzak/query_cache-config-disable"
Browse files Browse the repository at this point in the history
This reverts commit e60b786.
  • Loading branch information
jhawthorn committed Oct 31, 2024
1 parent 30f7974 commit 8984f4c
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 83 deletions.
6 changes: 0 additions & 6 deletions activerecord/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
## Rails 7.1.5 (October 30, 2024) ##

* Fix support for `query_cache: false` in `database.yml`.

`query_cache: false` would no longer entirely disable the Active Record query cache.

*zzak*

* Fix marshalling of unsaved associated records in 7.1 format.

The 7.1 format would only marshal associated records if the association was loaded.
Expand Down
5 changes: 1 addition & 4 deletions activerecord/lib/active_record/query_cache.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ def uncached(&block)
end

def self.run
ActiveRecord::Base.connection_handler.each_connection_pool.reject(&:query_cache_enabled).each do |pool|
next if pool.db_config&.query_cache == false
pool.enable_query_cache!
end
ActiveRecord::Base.connection_handler.each_connection_pool.reject { |p| p.query_cache_enabled }.each { |p| p.enable_query_cache! }
end

def self.complete(pools)
Expand Down
73 changes: 0 additions & 73 deletions activerecord/test/cases/query_cache_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,79 +123,6 @@ def test_query_cache_is_applied_to_all_connections
clean_up_connection_handler
end

def test_cache_is_not_applied_when_config_is_false
ActiveRecord::Base.connected_to(role: :reading) do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: false))
end

mw = middleware { |env|
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
assert_not_predicate pool.lease_connection, :query_cache_enabled
assert_nil pool.query_cache.instance_variable_get(:@max_size)
end
}

mw.call({})
ensure
clean_up_connection_handler
end

def test_cache_is_applied_when_config_is_string
ActiveRecord::Base.connected_to(role: :reading) do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: "unlimited"))
end

mw = middleware { |env|
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
assert_predicate pool.lease_connection, :query_cache_enabled
assert_nil pool.query_cache.instance_variable_get(:@max_size)
end
}

mw.call({})
ensure
clean_up_connection_handler
end

def test_cache_is_applied_when_config_is_integer
ActiveRecord::Base.connected_to(role: :reading) do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: 42))
end

mw = middleware { |env|
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
assert_predicate pool.lease_connection, :query_cache_enabled
assert_equal 42, pool.query_cache.instance_variable_get(:@max_size)
end
}

mw.call({})
ensure
clean_up_connection_handler
end

def test_cache_is_applied_when_config_is_nil
ActiveRecord::Base.connected_to(role: :reading) do
db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary")
ActiveRecord::Base.establish_connection(db_config.configuration_hash.merge(query_cache: nil))
end

mw = middleware { |env|
ActiveRecord::Base.connection_handler.connection_pool_list(:reading).each do |pool|
assert_predicate pool.lease_connection, :query_cache_enabled
end
}

mw.call({})
ensure
clean_up_connection_handler
end



if Process.respond_to?(:fork) && !in_memory_db?
def test_query_cache_with_forked_processes
ActiveRecord::Base.connected_to(role: :reading) do
Expand Down

0 comments on commit 8984f4c

Please sign in to comment.