mirror of https://github.com/rails/rails
Remove ability to specify a timestamp name for `#cache_key`
This commit is contained in:
parent
90d7842186
commit
0bef23e630
|
@ -1,3 +1,7 @@
|
|||
* Remove ability to specify a timestamp name for `#cache_key`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
||||
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
|
||||
|
||||
*Rafael Mendonça França*
|
||||
|
|
|
@ -61,23 +61,14 @@ module ActiveRecord
|
|||
#
|
||||
# Product.cache_versioning = false
|
||||
# Product.find(5).cache_key # => "products/5-20071224150000" (updated_at available)
|
||||
def cache_key(*timestamp_names)
|
||||
def cache_key
|
||||
if new_record?
|
||||
"#{model_name.cache_key}/new"
|
||||
else
|
||||
if cache_version && timestamp_names.none?
|
||||
if cache_version
|
||||
"#{model_name.cache_key}/#{id}"
|
||||
else
|
||||
timestamp = if timestamp_names.any?
|
||||
ActiveSupport::Deprecation.warn(<<-MSG.squish)
|
||||
Specifying a timestamp name for #cache_key has been deprecated in favor of
|
||||
the explicit #cache_version method that can be overwritten.
|
||||
MSG
|
||||
|
||||
max_updated_column_timestamp(timestamp_names)
|
||||
else
|
||||
max_updated_column_timestamp
|
||||
end
|
||||
timestamp = max_updated_column_timestamp
|
||||
|
||||
if timestamp
|
||||
timestamp = timestamp.utc.to_s(cache_timestamp_format)
|
||||
|
|
|
@ -133,11 +133,10 @@ module ActiveRecord
|
|||
self.class.send(:current_time_from_proper_timezone)
|
||||
end
|
||||
|
||||
def max_updated_column_timestamp(timestamp_names = timestamp_attributes_for_update_in_model)
|
||||
timestamp_names
|
||||
.map { |attr| self[attr] }
|
||||
def max_updated_column_timestamp
|
||||
timestamp_attributes_for_update_in_model
|
||||
.map { |attr| self[attr]&.to_time }
|
||||
.compact
|
||||
.map(&:to_time)
|
||||
.max
|
||||
end
|
||||
|
||||
|
|
|
@ -191,21 +191,6 @@ class IntegrationTest < ActiveRecord::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_named_timestamps_for_cache_key
|
||||
assert_deprecated do
|
||||
owner = owners(:blackbeard)
|
||||
assert_equal "owners/#{owner.id}-#{owner.happy_at.utc.to_s(:usec)}", owner.cache_key(:updated_at, :happy_at)
|
||||
end
|
||||
end
|
||||
|
||||
def test_cache_key_when_named_timestamp_is_nil
|
||||
assert_deprecated do
|
||||
owner = owners(:blackbeard)
|
||||
owner.happy_at = nil
|
||||
assert_equal "owners/#{owner.id}", owner.cache_key(:happy_at)
|
||||
end
|
||||
end
|
||||
|
||||
def test_cache_key_is_stable_with_versioning_on
|
||||
with_cache_versioning do
|
||||
developer = Developer.first
|
||||
|
|
Loading…
Reference in New Issue