diff options
author | Drew Blessing <drew.blessing@buckle.com> | 2013-12-11 09:30:22 -0600 |
---|---|---|
committer | Drew Blessing <drew.blessing@buckle.com> | 2013-12-11 09:30:22 -0600 |
commit | c26d392b1a160ae357a63cf160daeb81a0dd8ece (patch) | |
tree | 79104023aea917518515d66888b477f6e0f03fc9 /app | |
parent | 2934e7a9627bb92ab9367923cdbcbaa13f7843d4 (diff) | |
download | gitlab-ce-c26d392b1a160ae357a63cf160daeb81a0dd8ece.tar.gz |
Expire event cache on avatar creation/removal
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/profiles/avatars_controller.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 14 | ||||
-rw-r--r-- | app/uploaders/attachment_uploader.rb | 6 |
3 files changed, 22 insertions, 0 deletions
diff --git a/app/controllers/profiles/avatars_controller.rb b/app/controllers/profiles/avatars_controller.rb index e90eaafd440..57f3bbf0627 100644 --- a/app/controllers/profiles/avatars_controller.rb +++ b/app/controllers/profiles/avatars_controller.rb @@ -6,6 +6,8 @@ class Profiles::AvatarsController < ApplicationController @user.remove_avatar! @user.save + @user.reset_events_cache + redirect_to profile_path end end diff --git a/app/models/user.rb b/app/models/user.rb index f1f68d5f424..25a04089d33 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -404,4 +404,18 @@ class User < ActiveRecord::Base project.namespace != namespace && project.project_member(self) end + + # Reset project events cache related to this user + # + # Since we do cache @event we need to reset cache in special cases: + # * when the user changes their avatar + # Events cache stored like events/23-20130109142513. + # The cache key includes updated_at timestamp. + # Thus it will automatically generate a new fragment + # when the event is updated because the key changes. + def reset_events_cache + Event.where(author_id: self.id). + order('id DESC').limit(1000). + update_all(updated_at: Time.now) + end end diff --git a/app/uploaders/attachment_uploader.rb b/app/uploaders/attachment_uploader.rb index 98794c9470b..b122b6c8658 100644 --- a/app/uploaders/attachment_uploader.rb +++ b/app/uploaders/attachment_uploader.rb @@ -3,6 +3,8 @@ class AttachmentUploader < CarrierWave::Uploader::Base storage :file + after :store, :reset_events_cache + def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end @@ -27,4 +29,8 @@ class AttachmentUploader < CarrierWave::Uploader::Base def file_storage? self.class.storage == CarrierWave::Storage::File end + + def reset_events_cache(file) + model.reset_events_cache if model.is_a?(User) + end end |