mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #38099 from alipman88/avoid_unecessary_query_if_cache_versioning_enabled
Avoid unnecessary SQL query when calling ActiveRecord::Relation#cache_key
This commit is contained in:
commit
be40e8e5af
2 changed files with 8 additions and 1 deletions
|
@ -317,7 +317,7 @@ module ActiveRecord
|
|||
query_signature = ActiveSupport::Digest.hexdigest(to_sql)
|
||||
key = "#{klass.model_name.cache_key}/query-#{query_signature}"
|
||||
|
||||
if cache_version(timestamp_column)
|
||||
if collection_cache_versioning
|
||||
key
|
||||
else
|
||||
"#{key}-#{compute_cache_version(timestamp_column)}"
|
||||
|
|
|
@ -113,6 +113,13 @@ module ActiveRecord
|
|||
assert_no_queries { developers.cache_key }
|
||||
end
|
||||
|
||||
test "it doesn't trigger any query if collection_cache_versioning is enabled" do
|
||||
with_collection_cache_versioning do
|
||||
developers = Developer.where(name: "David")
|
||||
assert_no_queries { developers.cache_key }
|
||||
end
|
||||
end
|
||||
|
||||
test "relation cache_key changes when the sql query changes" do
|
||||
developers = Developer.where(name: "David")
|
||||
other_relation = Developer.where(name: "David").where("1 = 1")
|
||||
|
|
Loading…
Reference in a new issue