Commit adf55958 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge pull request #5759 from bke-drewb/issue-5496

Add cache expiry on avatar creation/removal
parents 2934e7a9 c26d392b
...@@ -9,6 +9,7 @@ v 6.4.0 ...@@ -9,6 +9,7 @@ v 6.4.0
- Allow removal of avatar (Drew Blessing) - Allow removal of avatar (Drew Blessing)
- Project web hooks now support issues and merge request events - 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) - 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 v 6.3.0
- API for adding gitlab-ci service - API for adding gitlab-ci service
......
...@@ -6,6 +6,8 @@ class Profiles::AvatarsController < ApplicationController ...@@ -6,6 +6,8 @@ class Profiles::AvatarsController < ApplicationController
@user.remove_avatar! @user.remove_avatar!
@user.save @user.save
@user.reset_events_cache
redirect_to profile_path redirect_to profile_path
end end
end end
...@@ -404,4 +404,18 @@ class User < ActiveRecord::Base ...@@ -404,4 +404,18 @@ class User < ActiveRecord::Base
project.namespace != namespace && project.namespace != namespace &&
project.project_member(self) project.project_member(self)
end 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 end
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
class AttachmentUploader < CarrierWave::Uploader::Base class AttachmentUploader < CarrierWave::Uploader::Base
storage :file storage :file
after :store, :reset_events_cache
def store_dir def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end end
...@@ -27,4 +29,8 @@ class AttachmentUploader < CarrierWave::Uploader::Base ...@@ -27,4 +29,8 @@ class AttachmentUploader < CarrierWave::Uploader::Base
def file_storage? def file_storage?
self.class.storage == CarrierWave::Storage::File self.class.storage == CarrierWave::Storage::File
end end
def reset_events_cache(file)
model.reset_events_cache if model.is_a?(User)
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment