Skip to content

Commit 0bef23e

Browse files
committed
Remove ability to specify a timestamp name for #cache_key
1 parent 90d7842 commit 0bef23e

4 files changed

Lines changed: 10 additions & 31 deletions

File tree

‎activerecord/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove ability to specify a timestamp name for `#cache_key`.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove deprecated `ActiveRecord::Migrator.migrations_path=`.
26

37
*Rafael Mendonça França*

‎activerecord/lib/active_record/integration.rb‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,14 @@ def to_param
6161
#
6262
# Product.cache_versioning = false
6363
# Product.find(5).cache_key # => "products/5-20071224150000" (updated_at available)
64-
def cache_key(*timestamp_names)
64+
def cache_key
6565
if new_record?
6666
"#{model_name.cache_key}/new"
6767
else
68-
if cache_version && timestamp_names.none?
68+
if cache_version
6969
"#{model_name.cache_key}/#{id}"
7070
else
71-
timestamp = if timestamp_names.any?
72-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
73-
Specifying a timestamp name for #cache_key has been deprecated in favor of
74-
the explicit #cache_version method that can be overwritten.
75-
MSG
76-
77-
max_updated_column_timestamp(timestamp_names)
78-
else
79-
max_updated_column_timestamp
80-
end
71+
timestamp = max_updated_column_timestamp
8172

8273
if timestamp
8374
timestamp = timestamp.utc.to_s(cache_timestamp_format)

‎activerecord/lib/active_record/timestamp.rb‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,10 @@ def current_time_from_proper_timezone
133133
self.class.send(:current_time_from_proper_timezone)
134134
end
135135

136-
def max_updated_column_timestamp(timestamp_names = timestamp_attributes_for_update_in_model)
137-
timestamp_names
138-
.map { |attr| self[attr] }
136+
def max_updated_column_timestamp
137+
timestamp_attributes_for_update_in_model
138+
.map { |attr| self[attr]&.to_time }
139139
.compact
140-
.map(&:to_time)
141140
.max
142141
end
143142

‎activerecord/test/cases/integration_test.rb‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,6 @@ def test_cache_version_format_is_not_too_precise
191191
end
192192
end
193193

194-
def test_named_timestamps_for_cache_key
195-
assert_deprecated do
196-
owner = owners(:blackbeard)
197-
assert_equal "owners/#{owner.id}-#{owner.happy_at.utc.to_s(:usec)}", owner.cache_key(:updated_at, :happy_at)
198-
end
199-
end
200-
201-
def test_cache_key_when_named_timestamp_is_nil
202-
assert_deprecated do
203-
owner = owners(:blackbeard)
204-
owner.happy_at = nil
205-
assert_equal "owners/#{owner.id}", owner.cache_key(:happy_at)
206-
end
207-
end
208-
209194
def test_cache_key_is_stable_with_versioning_on
210195
with_cache_versioning do
211196
developer = Developer.first

0 commit comments

Comments
 (0)