Skip to content

Commit

Permalink
Refactor logic to grab the max time of the list of timestamp names in…
Browse files Browse the repository at this point in the history
… #cache_key

Reuse the already existing logic used for grabbing this information from
the updated columns.
  • Loading branch information
carlosantoniodasilva committed Nov 4, 2013
1 parent 92c6305 commit d0d7555
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/integration.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def cache_key(*timestamp_names)
when new_record? when new_record?
"#{self.class.model_name.cache_key}/new" "#{self.class.model_name.cache_key}/new"
when timestamp_names.any? when timestamp_names.any?
timestamps = timestamp_names.collect { |method| send(method) }.compact timestamp = max_updated_column_timestamp(timestamp_names)
timestamp = timestamps.max.utc.to_s(cache_timestamp_format) timestamp = timestamp.utc.to_s(cache_timestamp_format)
"#{self.class.model_name.cache_key}/#{id}-#{timestamp}" "#{self.class.model_name.cache_key}/#{id}-#{timestamp}"
when timestamp = max_updated_column_timestamp when timestamp = max_updated_column_timestamp
timestamp = timestamp.utc.to_s(cache_timestamp_format) timestamp = timestamp.utc.to_s(cache_timestamp_format)
Expand Down
4 changes: 2 additions & 2 deletions activerecord/lib/active_record/timestamp.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def all_timestamp_attributes
timestamp_attributes_for_create + timestamp_attributes_for_update timestamp_attributes_for_create + timestamp_attributes_for_update
end end


def max_updated_column_timestamp def max_updated_column_timestamp(timestamp_names = timestamp_attributes_for_update)
if (timestamps = timestamp_attributes_for_update.map { |attr| self[attr] }.compact).present? if (timestamps = timestamp_names.map { |attr| self[attr] }.compact).present?
timestamps.map { |ts| ts.to_time }.max timestamps.map { |ts| ts.to_time }.max
end end
end end
Expand Down

0 comments on commit d0d7555

Please sign in to comment.