Skip to content

Commit

Permalink
Remove ability to specify a timestamp name for #cache_key
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelfranca committed Jan 17, 2019
1 parent 90d7842 commit 0bef23e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 31 deletions.
4 changes: 4 additions & 0 deletions activerecord/CHANGELOG.md
@@ -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*
Expand Down
15 changes: 3 additions & 12 deletions activerecord/lib/active_record/integration.rb
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions activerecord/lib/active_record/timestamp.rb
Expand Up @@ -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

Expand Down
15 changes: 0 additions & 15 deletions activerecord/test/cases/integration_test.rb
Expand Up @@ -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
Expand Down

0 comments on commit 0bef23e

Please sign in to comment.