diff options
author | Sean McGivern <sean@gitlab.com> | 2017-07-17 19:36:29 +0100 |
---|---|---|
committer | Fatih Acet <acetfatih@gmail.com> | 2017-07-21 22:35:26 +0300 |
commit | db0b7fb39e921728385b3287d206aabbeb88690e (patch) | |
tree | d2c1f43d192ce30cf3185cf104ec2ffcf1d02704 /app | |
parent | aed5632ca4d848ebc1e0cfed3465807cf36afe9e (diff) | |
download | gitlab-ce-db0b7fb39e921728385b3287d206aabbeb88690e.tar.gz |
Expire ETag cache on note when award emoji changes
Diffstat (limited to 'app')
-rw-r--r-- | app/models/award_emoji.rb | 9 | ||||
-rw-r--r-- | app/models/note.rb | 22 |
2 files changed, 20 insertions, 11 deletions
diff --git a/app/models/award_emoji.rb b/app/models/award_emoji.rb index 91b62dabbcd..1f07caf3366 100644 --- a/app/models/award_emoji.rb +++ b/app/models/award_emoji.rb @@ -17,6 +17,9 @@ class AwardEmoji < ActiveRecord::Base scope :downvotes, -> { where(name: DOWNVOTE_NAME) } scope :upvotes, -> { where(name: UPVOTE_NAME) } + after_save :expire_etag_cache + after_destroy :expire_etag_cache + class << self def votes_for_collection(ids, type) select('name', 'awardable_id', 'COUNT(*) as count') @@ -32,4 +35,10 @@ class AwardEmoji < ActiveRecord::Base def upvote? self.name == UPVOTE_NAME end + + def expire_etag_cache + return unless awardable.is_a?(Note) + + awardable.expire_etag_cache + end end diff --git a/app/models/note.rb b/app/models/note.rb index d0e3bc0bfed..0e120e7de16 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -299,6 +299,17 @@ class Note < ActiveRecord::Base end end + def expire_etag_cache + return unless for_issue? + + key = Gitlab::Routing.url_helpers.project_noteable_notes_path( + noteable.project, + target_type: noteable_type.underscore, + target_id: noteable.id + ) + Gitlab::EtagCaching::Store.new.touch(key) + end + private def keep_around_commit @@ -326,15 +337,4 @@ class Note < ActiveRecord::Base def set_discussion_id self.discussion_id ||= discussion_class.discussion_id(self) end - - def expire_etag_cache - return unless for_issue? - - key = Gitlab::Routing.url_helpers.project_noteable_notes_path( - noteable.project, - target_type: noteable_type.underscore, - target_id: noteable.id - ) - Gitlab::EtagCaching::Store.new.touch(key) - end end |