Permalink
Browse files

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.
  • Loading branch information...
1 parent 92c6305 commit d0d7555e8771414bdcf62ef0192ce8d8b6284219 @carlosantoniodasilva carlosantoniodasilva committed Nov 4, 2013
Showing with 4 additions and 4 deletions.
  1. +2 −2 activerecord/lib/active_record/integration.rb
  2. +2 −2 activerecord/lib/active_record/timestamp.rb
@@ -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

0 comments on commit d0d7555

Please sign in to comment.