diff options
author | Ahmad Sherif <me@ahmadsherif.com> | 2016-07-21 20:15:31 +0300 |
---|---|---|
committer | Ahmad Sherif <me@ahmadsherif.com> | 2016-07-21 22:17:25 +0300 |
commit | 0c14c6332d38704a7bfd8916a8deedd5c5808978 (patch) | |
tree | bb877c98ef54f225ec13196c06d2f398c9131ec4 /lib/banzai | |
parent | 89292551295418cf4b5b90ce904a6b41f19a8be3 (diff) |
Retrieve rendered HTML from cache in one request
See #19985
Diffstat (limited to 'lib/banzai')
-rw-r--r-- | lib/banzai/reference_extractor.rb | 9 |
1 files changed, 5 insertions, 4 deletions
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 |