Invalidate ETag cache when note changes
This commit is contained in:
parent
61c9604721
commit
c661df3561
2 changed files with 25 additions and 0 deletions
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue