summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2017-02-08 18:04:16 +0100
committerAdam Niedzielski <adamsunday@gmail.com>2017-03-01 16:48:02 +0100
commitc661df356156240deeef7c2734670ba5f2b4b04b (patch)
tree26916ddd7277ac1b5a11d8d3a0433204a97b8ec4
parent61c9604721dbda53eb4a7111d16c1b19292f9766 (diff)
downloadgitlab-ce-c661df356156240deeef7c2734670ba5f2b4b04b.tar.gz
Invalidate ETag cache when note changes
-rw-r--r--app/models/note.rb13
-rw-r--r--spec/models/note_spec.rb12
2 files changed, 25 insertions, 0 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 4c97e4a986c..e22e96aec6f 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -85,6 +85,7 @@ class Note < ActiveRecord::Base
before_validation :nullify_blank_type, :nullify_blank_line_code
before_validation :set_discussion_id
after_save :keep_around_commit, unless: :for_personal_snippet?
+ after_save :expire_etag_cache
class << self
def model_name
@@ -272,4 +273,16 @@ class Note < ActiveRecord::Base
self.class.build_discussion_id(noteable_type, noteable_id || commit_id)
end
end
+
+ def expire_etag_cache
+ return unless for_issue?
+
+ key = Gitlab::Routing.url_helpers.namespace_project_noteable_notes_path(
+ noteable.project.namespace,
+ noteable.project,
+ target_type: noteable_type.underscore,
+ target_id: noteable.id
+ )
+ Gitlab::EtagCaching::Store.new.touch(key)
+ end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 1cde9e04951..33536487c41 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -387,4 +387,16 @@ describe Note, models: true do
end
end
end
+
+ describe 'expiring ETag cache' do
+ let(:note) { build(:note_on_issue) }
+
+ it "expires cache for note's issue when note is saved" do
+ expect_any_instance_of(Gitlab::EtagCaching::Store)
+ .to receive(:touch)
+ .with("/#{note.project.namespace.to_param}/#{note.project.to_param}/noteable/issue/#{note.noteable.id}/notes")
+
+ note.save!
+ end
+ end
end