Commit c661df35 authored by Adam Niedzielski's avatar Adam Niedzielski

Invalidate ETag cache when note changes

parent 61c96047
...@@ -85,6 +85,7 @@ class Note < ActiveRecord::Base ...@@ -85,6 +85,7 @@ class Note < ActiveRecord::Base
before_validation :nullify_blank_type, :nullify_blank_line_code before_validation :nullify_blank_type, :nullify_blank_line_code
before_validation :set_discussion_id before_validation :set_discussion_id
after_save :keep_around_commit, unless: :for_personal_snippet? after_save :keep_around_commit, unless: :for_personal_snippet?
after_save :expire_etag_cache
class << self class << self
def model_name def model_name
...@@ -272,4 +273,16 @@ class Note < ActiveRecord::Base ...@@ -272,4 +273,16 @@ class Note < ActiveRecord::Base
self.class.build_discussion_id(noteable_type, noteable_id || commit_id) self.class.build_discussion_id(noteable_type, noteable_id || commit_id)
end end
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 end
...@@ -387,4 +387,16 @@ describe Note, models: true do ...@@ -387,4 +387,16 @@ describe Note, models: true do
end end
end 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 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