mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-12 06:06:05 +10:00
Merge branch 'fix-banzai-cache' into 'master'
Fix mentionable reference extraction caching. Fixes https://gitlab.com/gitlab-org/gitlab-ce/issues/4130 Reverts https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2120 and https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/2283 See merge request !2315
This commit is contained in:
@@ -51,8 +51,11 @@ module Mentionable
|
||||
else
|
||||
self.class.mentionable_attrs.each do |attr, options|
|
||||
text = send(attr)
|
||||
options[:cache_key] = [self, attr] if options.delete(:cache) && self.persisted?
|
||||
ext.analyze(text, options)
|
||||
|
||||
context = options.dup
|
||||
context[:cache_key] = [self, attr] if context.delete(:cache) && self.persisted?
|
||||
|
||||
ext.analyze(text, context)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+5
-14
@@ -18,22 +18,13 @@ module Banzai
|
||||
cache_key = context.delete(:cache_key)
|
||||
cache_key = full_cache_key(cache_key, context[:pipeline])
|
||||
|
||||
cacheless = cacheless_render(text, context)
|
||||
|
||||
if cache_key && ENV["DEBUG_BANZAI_CACHE"]
|
||||
cached = Rails.cache.fetch(cache_key) { cacheless }
|
||||
|
||||
if cached != cacheless
|
||||
Rails.logger.warn "Banzai cache mismatch"
|
||||
Rails.logger.warn "Text: #{text.inspect}"
|
||||
Rails.logger.warn "Context: #{context.inspect}"
|
||||
Rails.logger.warn "Cache key: #{cache_key.inspect}"
|
||||
Rails.logger.warn "Cacheless: #{cacheless.inspect}"
|
||||
Rails.logger.warn "With cache: #{cached.inspect}"
|
||||
if cache_key
|
||||
Rails.cache.fetch(cache_key) do
|
||||
cacheless_render(text, context)
|
||||
end
|
||||
else
|
||||
cacheless_render(text, context)
|
||||
end
|
||||
|
||||
cacheless
|
||||
end
|
||||
|
||||
def self.render_result(text, context = {})
|
||||
|
||||
@@ -125,6 +125,19 @@ describe Note, models: true do
|
||||
let(:set_mentionable_text) { ->(txt) { subject.note = txt } }
|
||||
end
|
||||
|
||||
describe "#all_references" do
|
||||
let!(:note1) { create(:note) }
|
||||
let!(:note2) { create(:note) }
|
||||
|
||||
it "reads the rendered note body from the cache" do
|
||||
expect(Banzai::Renderer).to receive(:render).with(note1.note, pipeline: :note, cache_key: [note1, "note"], project: note1.project)
|
||||
expect(Banzai::Renderer).to receive(:render).with(note2.note, pipeline: :note, cache_key: [note2, "note"], project: note2.project)
|
||||
|
||||
note1.all_references
|
||||
note2.all_references
|
||||
end
|
||||
end
|
||||
|
||||
describe :search do
|
||||
let!(:note) { create(:note, note: "WoW") }
|
||||
|
||||
@@ -164,7 +177,7 @@ describe Note, models: true do
|
||||
expect(note.editable?).to be_falsy
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
describe "set_award!" do
|
||||
let(:issue) { create :issue }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user