1
0
Fork 0
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:
Carlos Antonio da Silva 2013-11-04 13:14:06 -02:00
parent 92c6305954
commit d0d7555e87
2 changed files with 4 additions and 4 deletions

View file

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

View file

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