Commit 623fa2ca authored by Robert Speicher's avatar Robert Speicher

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
parents bcd2a09d 18b17072
...@@ -51,8 +51,11 @@ module Mentionable ...@@ -51,8 +51,11 @@ module Mentionable
else else
self.class.mentionable_attrs.each do |attr, options| self.class.mentionable_attrs.each do |attr, options|
text = send(attr) 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
end end
......
...@@ -18,22 +18,13 @@ module Banzai ...@@ -18,22 +18,13 @@ module Banzai
cache_key = context.delete(:cache_key) cache_key = context.delete(:cache_key)
cache_key = full_cache_key(cache_key, context[:pipeline]) cache_key = full_cache_key(cache_key, context[:pipeline])
cacheless = cacheless_render(text, context) if cache_key
Rails.cache.fetch(cache_key) do
if cache_key && ENV["DEBUG_BANZAI_CACHE"] cacheless_render(text, context)
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}"
end end
else
cacheless_render(text, context)
end end
cacheless
end end
def self.render_result(text, context = {}) def self.render_result(text, context = {})
......
...@@ -125,6 +125,19 @@ describe Note, models: true do ...@@ -125,6 +125,19 @@ describe Note, models: true do
let(:set_mentionable_text) { ->(txt) { subject.note = txt } } let(:set_mentionable_text) { ->(txt) { subject.note = txt } }
end 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 describe :search do
let!(:note) { create(:note, note: "WoW") } let!(:note) { create(:note, note: "WoW") }
...@@ -164,7 +177,7 @@ describe Note, models: true do ...@@ -164,7 +177,7 @@ describe Note, models: true do
expect(note.editable?).to be_falsy expect(note.editable?).to be_falsy
end end
end end
describe "set_award!" do describe "set_award!" do
let(:issue) { create :issue } let(:issue) { create :issue }
......
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