Commit c26d392b1a160ae357a63cf160daeb81a0dd8ece
1 parent
2934e7a9
Exists in
master
and in
4 other branches
Expire event cache on avatar creation/removal
Showing
4 changed files
with
23 additions
and
0 deletions
Show diff stats
CHANGELOG
... | ... | @@ -9,6 +9,7 @@ v 6.4.0 |
9 | 9 | - Allow removal of avatar (Drew Blessing) |
10 | 10 | - Project web hooks now support issues and merge request events |
11 | 11 | - Visiting project page while not logged in will redirect to sign-in instead of 404 (Jason Hollingsworth) |
12 | + - Expire event cache on avatar creation/removal (Drew Blessing) | |
12 | 13 | |
13 | 14 | v 6.3.0 |
14 | 15 | - API for adding gitlab-ci service | ... | ... |
app/controllers/profiles/avatars_controller.rb
app/models/user.rb
... | ... | @@ -404,4 +404,18 @@ class User < ActiveRecord::Base |
404 | 404 | project.namespace != namespace && |
405 | 405 | project.project_member(self) |
406 | 406 | end |
407 | + | |
408 | + # Reset project events cache related to this user | |
409 | + # | |
410 | + # Since we do cache @event we need to reset cache in special cases: | |
411 | + # * when the user changes their avatar | |
412 | + # Events cache stored like events/23-20130109142513. | |
413 | + # The cache key includes updated_at timestamp. | |
414 | + # Thus it will automatically generate a new fragment | |
415 | + # when the event is updated because the key changes. | |
416 | + def reset_events_cache | |
417 | + Event.where(author_id: self.id). | |
418 | + order('id DESC').limit(1000). | |
419 | + update_all(updated_at: Time.now) | |
420 | + end | |
407 | 421 | end | ... | ... |
app/uploaders/attachment_uploader.rb
... | ... | @@ -3,6 +3,8 @@ |
3 | 3 | class AttachmentUploader < CarrierWave::Uploader::Base |
4 | 4 | storage :file |
5 | 5 | |
6 | + after :store, :reset_events_cache | |
7 | + | |
6 | 8 | def store_dir |
7 | 9 | "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" |
8 | 10 | end |
... | ... | @@ -27,4 +29,8 @@ class AttachmentUploader < CarrierWave::Uploader::Base |
27 | 29 | def file_storage? |
28 | 30 | self.class.storage == CarrierWave::Storage::File |
29 | 31 | end |
32 | + | |
33 | + def reset_events_cache(file) | |
34 | + model.reset_events_cache if model.is_a?(User) | |
35 | + end | |
30 | 36 | end | ... | ... |