Commit 990a2a7b authored by Sean McGivern's avatar Sean McGivern

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.
parent 4d6d1f05
---
title: Remove performance bottleneck preventing large wiki pages from displaying
merge_request: 20174
author:
type: performance
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment