提交 f656bb30 编写于 作者: R Ryuta Kamizono

Deprecate `collection_cache_key` which is private API

The `collection_cache_key` is private API for a long time, but I've
maintained it in #35848 since it is mentioned in the doc
(https://github.com/rails/rails/pull/35848#discussion_r272011475).

The doc has removed at 1da9a7e4, so there is no longer a reason to
maintain that private API.
上级 10da0a27
# frozen_string_literal: true
require "active_support/core_ext/string/filters"
require "active_support/deprecation"
module ActiveRecord
module Integration
......@@ -162,8 +163,9 @@ def to_param(method_name = nil)
end
def collection_cache_key(collection = all, timestamp_column = :updated_at) # :nodoc:
collection.compute_cache_key(timestamp_column)
collection.send(:compute_cache_key, timestamp_column)
end
deprecate :collection_cache_key
end
private
......
......@@ -310,7 +310,7 @@ def many?
# Product.where("name like ?", "%Game%").cache_key(:last_reviewed_at)
def cache_key(timestamp_column = :updated_at)
@cache_keys ||= {}
@cache_keys[timestamp_column] ||= @klass.collection_cache_key(self, timestamp_column)
@cache_keys[timestamp_column] ||= compute_cache_key(timestamp_column)
end
def compute_cache_key(timestamp_column = :updated_at) # :nodoc:
......@@ -323,6 +323,7 @@ def compute_cache_key(timestamp_column = :updated_at) # :nodoc:
"#{key}-#{compute_cache_version(timestamp_column)}"
end
end
private :compute_cache_key
# Returns a cache version that can be used together with the cache key to form
# a recyclable caching scheme. The cache version is built with the number of records
......@@ -382,6 +383,7 @@ def compute_cache_version(timestamp_column) # :nodoc:
"#{size}"
end
end
private :compute_cache_version
# Scope all queries to the current scope.
#
......
......@@ -13,7 +13,9 @@ class CollectionCacheKeyTest < ActiveRecord::TestCase
fixtures :developers, :projects, :developers_projects, :topics, :comments, :posts
test "collection_cache_key on model" do
assert_match(/\Adevelopers\/query-(\h+)-(\d+)-(\d+)\z/, Developer.collection_cache_key)
assert_deprecated do
assert_match(/\Adevelopers\/query-(\h+)-(\d+)-(\d+)\z/, Developer.collection_cache_key)
end
end
test "cache_key for relation" do
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册