summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAhmad Sherif <me@ahmadsherif.com>2016-07-21 19:15:31 +0200
committerAhmad Sherif <me@ahmadsherif.com>2016-07-21 21:17:25 +0200
commit0c14c6332d38704a7bfd8916a8deedd5c5808978 (patch)
treebb877c98ef54f225ec13196c06d2f398c9131ec4
parent89292551295418cf4b5b90ce904a6b41f19a8be3 (diff)
downloadgitlab-ce-fix/get-cached-rendered-html-using-single-redis-request.tar.gz
Retrieve rendered HTML from cache in one requestfix/get-cached-rendered-html-using-single-redis-request
See #19985
-rw-r--r--CHANGELOG1
-rw-r--r--lib/banzai/reference_extractor.rb9
-rw-r--r--spec/models/note_spec.rb40
3 files changed, 30 insertions, 20 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 017cf92160f..8fe2caac7bd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.11.0 (unreleased)
- Fix of 'Commits being passed to custom hooks are already reachable when using the UI'
- Limit git rev-list output count to one in forced push check
+ - Retrieve rendered HTML from cache in one request
v 8.10.0 (unreleased)
- Fix profile activity heatmap to show correct day name (eanplatter)
diff --git a/lib/banzai/reference_extractor.rb b/lib/banzai/reference_extractor.rb
index bf366962aef..b26a41a1f3b 100644
--- a/lib/banzai/reference_extractor.rb
+++ b/lib/banzai/reference_extractor.rb
@@ -2,11 +2,11 @@ module Banzai
# Extract possible GFM references from an arbitrary String for further processing.
class ReferenceExtractor
def initialize
- @texts = []
+ @texts_and_contexts = []
end
def analyze(text, context = {})
- @texts << Renderer.render(text, context)
+ @texts_and_contexts << { text: text, context: context }
end
def references(type, project, current_user = nil)
@@ -21,9 +21,10 @@ module Banzai
def html_documents
# This ensures that we don't memoize anything until we have a number of
# text blobs to parse.
- return [] if @texts.empty?
+ return [] if @texts_and_contexts.empty?
- @html_documents ||= @texts.map { |html| Nokogiri::HTML.fragment(html) }
+ @html_documents ||= Renderer.cache_collection_render(@texts_and_contexts)
+ .map { |html| Nokogiri::HTML.fragment(html) }
end
end
end
diff --git a/spec/models/note_spec.rb b/spec/models/note_spec.rb
index 7d0697dab42..1243f5420a7 100644
--- a/spec/models/note_spec.rb
+++ b/spec/models/note_spec.rb
@@ -135,22 +135,30 @@ describe Note, models: true do
let!(:note2) { create(:note_on_issue) }
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,
- author: note1.author)
-
- expect(Banzai::Renderer).to receive(:render).
- with(note2.note,
- pipeline: :note,
- cache_key: [note2, "note"],
- project: note2.project,
- author: note2.author)
-
- note1.all_references
- note2.all_references
+ expect(Banzai::Renderer).to receive(:cache_collection_render).
+ with([{
+ text: note1.note,
+ context: {
+ pipeline: :note,
+ cache_key: [note1, "note"],
+ project: note1.project,
+ author: note1.author
+ }
+ }]).and_call_original
+
+ expect(Banzai::Renderer).to receive(:cache_collection_render).
+ with([{
+ text: note2.note,
+ context: {
+ pipeline: :note,
+ cache_key: [note2, "note"],
+ project: note2.project,
+ author: note2.author
+ }
+ }]).and_call_original
+
+ note1.all_references.users
+ note2.all_references.users
end
end