Skip to content

Commit a807d58

Browse files
authored
Merge pull request rails#53491 from zzak/query_cache-url_config
Cast `query_cache` value when using URL configuration
2 parents 55d1bf8 + af9b0f2 commit a807d58

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Cast `query_cache` value when using URL configuration.
2+
3+
*zzak*
4+
15
* NULLS NOT DISTINCT works with UNIQUE CONSTRAINT as well as UNIQUE INDEX.
26

37
*Ryuta Kamizono*

activerecord/lib/active_record/database_configurations/url_config.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ def initialize(env_name, name, url, configuration_hash = {})
4747
@configuration_hash[:schema_dump] = false
4848
end
4949

50-
if @configuration_hash[:query_cache] == "false"
51-
@configuration_hash[:query_cache] = false
52-
end
50+
query_cache = parse_query_cache
51+
@configuration_hash[:query_cache] = query_cache unless query_cache.nil?
5352

5453
to_boolean!(@configuration_hash, :replica)
5554
to_boolean!(@configuration_hash, :database_tasks)
@@ -58,6 +57,17 @@ def initialize(env_name, name, url, configuration_hash = {})
5857
end
5958

6059
private
60+
def parse_query_cache
61+
case value = @configuration_hash[:query_cache]
62+
when /\A\d+\z/
63+
value.to_i
64+
when "false"
65+
false
66+
else
67+
value
68+
end
69+
end
70+
6171
def to_boolean!(configuration_hash, key)
6272
if configuration_hash[key].is_a?(String)
6373
configuration_hash[key] = configuration_hash[key] != "false"

activerecord/test/cases/database_configurations/url_config_test.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ def test_query_cache_parsing
2121
assert_equal false, config.query_cache
2222

2323
config = UrlConfig.new("default_env", "primary", "postgres://localhost/foo?query_cache=42", {})
24-
assert_equal "42", config.query_cache
24+
assert_equal 42, config.query_cache
25+
26+
config = UrlConfig.new("default_env", "primary", "postgres://localhost/foo?query_cache=forever", {})
27+
assert_equal "forever", config.query_cache
2528
end
2629

2730
def test_replica_parsing

0 commit comments

Comments
 (0)