mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor logic to grab the max time of the list of timestamp names in #cache_key
Reuse the already existing logic used for grabbing this information from the updated columns.
This commit is contained in:
parent
92c6305954
commit
d0d7555e87
2 changed files with 4 additions and 4 deletions
|
@ -55,8 +55,8 @@ module ActiveRecord
|
|||
when new_record?
|
||||
"#{self.class.model_name.cache_key}/new"
|
||||
when timestamp_names.any?
|
||||
timestamps = timestamp_names.collect { |method| send(method) }.compact
|
||||
timestamp = timestamps.max.utc.to_s(cache_timestamp_format)
|
||||
timestamp = max_updated_column_timestamp(timestamp_names)
|
||||
timestamp = timestamp.utc.to_s(cache_timestamp_format)
|
||||
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
|
||||
when timestamp = max_updated_column_timestamp
|
||||
timestamp = timestamp.utc.to_s(cache_timestamp_format)
|
||||
|
|
|
@ -98,8 +98,8 @@ module ActiveRecord
|
|||
timestamp_attributes_for_create + timestamp_attributes_for_update
|
||||
end
|
||||
|
||||
def max_updated_column_timestamp
|
||||
if (timestamps = timestamp_attributes_for_update.map { |attr| self[attr] }.compact).present?
|
||||
def max_updated_column_timestamp(timestamp_names = timestamp_attributes_for_update)
|
||||
if (timestamps = timestamp_names.map { |attr| self[attr] }.compact).present?
|
||||
timestamps.map { |ts| ts.to_time }.max
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue