Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/profiles/avatars_controller.rb2
-rw-r--r--app/models/user.rb14
-rw-r--r--app/uploaders/attachment_uploader.rb6
4 files changed, 23 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3fa5143d43f..e62697410a8 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,7 @@ v 6.4.0
- Allow removal of avatar (Drew Blessing)
- Project web hooks now support issues and merge request events
- Visiting project page while not logged in will redirect to sign-in instead of 404 (Jason Hollingsworth)
+ - Expire event cache on avatar creation/removal (Drew Blessing)
v 6.3.0
- API for adding gitlab-ci service
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