summaryrefslogtreecommitdiff
path: root/lib/banzai
diff options
context:
space:
mode:
authorSean McGivern <sean@gitlab.com>2018-06-26 12:09:36 +0100
committerSean McGivern <sean@gitlab.com>2018-06-26 12:09:36 +0100
commit990a2a7b1d9be68f233a821b78abba06c35c03e8 (patch)
treebc31fb1f1f566fec54f0482d2948fcfbf6e20d9f /lib/banzai
parent4d6d1f0513b17617c48f25696f5eb173e430249e (diff)
downloadgitlab-ce-990a2a7b1d9be68f233a821b78abba06c35c03e8.tar.gz
Fix performance bottleneck when rendering large wiki pages
`Nokogiri::XML::Node#ancestors` appears to be much slower than `HTML::Pipeline::Filter#has_ancestor?` for these purposes. We already use `#has_ancestor?` elsewhere, so this change also makes this filter more consistent with other banzai filters.
Diffstat (limited to 'lib/banzai')
-rw-r--r--lib/banzai/filter/gollum_tags_filter.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/banzai/filter/gollum_tags_filter.rb b/lib/banzai/filter/gollum_tags_filter.rb
index 4bc82ecb4d6..bb9f488cd87 100644
--- a/lib/banzai/filter/gollum_tags_filter.rb
+++ b/lib/banzai/filter/gollum_tags_filter.rb
@@ -56,10 +56,12 @@ module Banzai
# Pattern to match allowed image extensions
ALLOWED_IMAGE_EXTENSIONS = /.+(jpg|png|gif|svg|bmp)\z/i.freeze
+ # Do not perform linking inside these tags.
+ IGNORED_ANCESTOR_TAGS = %w(pre code tt).to_set
+
def call
doc.search(".//text()").each do |node|
- # Do not perform linking inside <code> blocks
- next unless node.ancestors('code').empty?
+ next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS)
# A Gollum ToC tag is `[[_TOC_]]`, but due to MarkdownFilter running
# before this one, it will be converted into `[[<em>TOC</em>]]`, so it