Skip to content
Permalink
Browse files
Remove ability to specify a timestamp name for #cache_key
  • Loading branch information
rafaelfranca committed Jan 17, 2019
1 parent 90d7842 commit 0bef23e630f62e38f20b5ae1d1d5dbfb087050ea
@@ -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 @@ def to_param
#
# 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 @@ def current_time_from_proper_timezone
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 @@ def test_cache_version_format_is_not_too_precise
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

0 comments on commit 0bef23e

Please sign in to comment.