Remove ability to specify a timestamp name for `#cache_key`

This commit is contained in:
Rafael Mendonça França 2019-01-14 16:15:09 -05:00
parent 90d7842186
commit 0bef23e630
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
4 changed files with 10 additions and 31 deletions

View File

@ -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*

View File

@ -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)

View File

@ -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

View File

@ -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