diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-03-07 13:28:46 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2013-03-07 13:28:46 -0300 |
commit | 2e3e171e311d158cd22e70f1760f3c5c35729e6c (patch) | |
tree | ac3dff62dd1b3fdef0a509c4447d9bc617e81fdd /activerecord/lib | |
parent | d3adfd6d3b6bb07f4e4d56b017eff1ff740523ff (diff) | |
parent | 1dc98c143c4bf84ccfb55b30c7d41b29b62d50cf (diff) | |
download | rails-2e3e171e311d158cd22e70f1760f3c5c35729e6c.tar.gz rails-2e3e171e311d158cd22e70f1760f3c5c35729e6c.tar.bz2 rails-2e3e171e311d158cd22e70f1760f3c5c35729e6c.zip |
Merge pull request #9105 from bemurphy/cache_key_updated_on
cache_key consults updated_on timestamp if present
Conflicts:
activerecord/CHANGELOG.md
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/integration.rb | 2 | ||||
-rw-r--r-- | activerecord/lib/active_record/timestamp.rb | 6 |
2 files changed, 7 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/integration.rb b/activerecord/lib/active_record/integration.rb index 32d35f0ec1..48c73d7781 100644 --- a/activerecord/lib/active_record/integration.rb +++ b/activerecord/lib/active_record/integration.rb @@ -49,7 +49,7 @@ module ActiveRecord case when new_record? "#{self.class.model_name.cache_key}/new" - when timestamp = self[:updated_at] + when timestamp = max_updated_column_timestamp timestamp = timestamp.utc.to_s(cache_timestamp_format) "#{self.class.model_name.cache_key}/#{id}-#{timestamp}" else diff --git a/activerecord/lib/active_record/timestamp.rb b/activerecord/lib/active_record/timestamp.rb index 8ded6d4a86..ae99cff35e 100644 --- a/activerecord/lib/active_record/timestamp.rb +++ b/activerecord/lib/active_record/timestamp.rb @@ -98,6 +98,12 @@ 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? + timestamps.map { |ts| ts.to_time }.max + end + end + def current_time_from_proper_timezone self.class.default_timezone == :utc ? Time.now.utc : Time.now end |