diff options
author | Robert Speicher <robert@gitlab.com> | 2016-01-06 18:11:46 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-01-06 18:11:46 +0000 |
commit | 623fa2caf70f9d1eef63fdbee448adedc4c0ede8 (patch) | |
tree | 8b6c1b25070f529927ffb5e1ba66b566f5972f84 | |
parent | bcd2a09da72d430773b4b4bbc700132aade641d7 (diff) | |
parent | 18b17072c6cc7eb199d1da34a3ea481dcd53a8cf (diff) | |
download | gitlab-ce-623fa2caf70f9d1eef63fdbee448adedc4c0ede8.tar.gz |
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
-rw-r--r-- | app/models/concerns/mentionable.rb | 7 | ||||
-rw-r--r-- | lib/banzai/renderer.rb | 19 | ||||
-rw-r--r-- | spec/models/note_spec.rb | 15 |
3 files changed, 24 insertions, 17 deletions
diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 6316ee208b5..98f71ae8cb0 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -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 diff --git a/lib/banzai/renderer.rb b/lib/banzai/renderer.rb index 910e1c6994e..891c0fd7749 100644 --- a/lib/banzai/renderer.rb +++ b/lib/banzai/renderer.rb @@ -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 = {}) diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb index 593d8f76215..151a29e974b 100644 --- a/spec/models/note_spec.rb +++ b/spec/models/note_spec.rb @@ -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 } |