summaryrefslogtreecommitdiff
path: root/lib/gitlab/reference_extractor.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-10-13 22:53:05 +0200
committerDouwe Maan <douwe@gitlab.com>2015-10-13 22:53:05 +0200
commit93fcddd7a7ce4ed259794a4511ae04035ae33be2 (patch)
treee866959ff93d0e473e993b4bd727f92aad0fac7c /lib/gitlab/reference_extractor.rb
parent251e13666d04a1c8427401962e3e171e569d9088 (diff)
downloadgitlab-ce-93fcddd7a7ce4ed259794a4511ae04035ae33be2.tar.gz
Allow ReferenceExtractor to efficiently load references from multiple texts at once
Diffstat (limited to 'lib/gitlab/reference_extractor.rb')
-rw-r--r--lib/gitlab/reference_extractor.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/gitlab/reference_extractor.rb b/lib/gitlab/reference_extractor.rb
index 2e546ef0d54..8100f2675a7 100644
--- a/lib/gitlab/reference_extractor.rb
+++ b/lib/gitlab/reference_extractor.rb
@@ -10,9 +10,10 @@ module Gitlab
@current_user = current_user
end
- def analyze(text)
+ def analyze(texts)
references.clear
- @text = Gitlab::Markdown.render_without_gfm(text)
+ texts = Array(texts)
+ @texts = texts.map { |text| Gitlab::Markdown.render_without_gfm(text) }
end
%i(user label issue merge_request snippet commit commit_range).each do |type|
@@ -47,13 +48,25 @@ module Gitlab
current_user: current_user,
# We don't actually care about the links generated
only_path: true,
- ignore_blockquotes: true
+ ignore_blockquotes: true,
+ load_lazy_references: false
}
pipeline = HTML::Pipeline.new([filter, Gitlab::Markdown::ReferenceGathererFilter], context)
- result = pipeline.call(@text)
- result[:references][filter_type]
+ values = []
+ lazy_references = []
+
+ @texts.each do |text|
+ result = pipeline.call(text)
+
+ values.concat(result[:references][filter_type])
+ lazy_references.concat(result[:lazy_references][filter_type])
+ end
+
+ lazy_values = Gitlab::Markdown::ReferenceFilter::LazyReference.load(lazy_references)
+ values.concat(lazy_values)
+ values
end
end
end