提交 d0d7555e 编写于 作者: C Carlos Antonio da Silva

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.
上级 92c63059
......@@ -55,8 +55,8 @@ def cache_key(*timestamp_names)
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 @@ def all_timestamp_attributes
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册