diff options
author | Sean McGivern <sean@gitlab.com> | 2018-06-26 12:09:36 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2018-06-26 12:09:36 +0100 |
commit | 990a2a7b1d9be68f233a821b78abba06c35c03e8 (patch) | |
tree | bc31fb1f1f566fec54f0482d2948fcfbf6e20d9f | |
parent | 4d6d1f0513b17617c48f25696f5eb173e430249e (diff) | |
download | gitlab-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.
-rw-r--r-- | changelogs/unreleased/48269-wiki-page-returns-error-code-502.yml | 5 | ||||
-rw-r--r-- | lib/banzai/filter/gollum_tags_filter.rb | 6 |
2 files changed, 9 insertions, 2 deletions
diff --git a/changelogs/unreleased/48269-wiki-page-returns-error-code-502.yml b/changelogs/unreleased/48269-wiki-page-returns-error-code-502.yml new file mode 100644 index 00000000000..d3830e5b8c6 --- /dev/null +++ b/changelogs/unreleased/48269-wiki-page-returns-error-code-502.yml @@ -0,0 +1,5 @@ +--- +title: Remove performance bottleneck preventing large wiki pages from displaying +merge_request: 20174 +author: +type: performance 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 |