From d0d7555e8771414bdcf62ef0192ce8d8b6284219 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Mon, 4 Nov 2013 13:14:06 -0200 Subject: [PATCH] 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. --- activerecord/lib/active_record/integration.rb | 4 ++-- activerecord/lib/active_record/timestamp.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index 94abdb3ec7..f88c8e30e6 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -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) diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 9253150c4f..e0541b7681 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -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