Commit e8e4dbc1 authored by Stan Hu's avatar Stan Hu Committed by Yorick Peterse

Merge branch 'fix-inline-filter-speed' into 'master'

Fix serious performance bug with rendering Markdown with InlineDiffFilter

Nokogiri's `node.replace` was being unnecessarily called for every text node in
the document due to a comparison bug. The code previously was comparing the
HTML representation of the full document against the text node, which would
always fail. Fix the comparison to just compare the modified text.

Closes #18011

See merge request !4392
parent 3799edd7
...@@ -15,6 +15,7 @@ v 8.8.3 ...@@ -15,6 +15,7 @@ v 8.8.3
- Fix incorrect links on pipeline page when merge request created from fork. !4376 - Fix incorrect links on pipeline page when merge request created from fork. !4376
- Use downcased path to container repository as this is expected path by Docker. !4420 - Use downcased path to container repository as this is expected path by Docker. !4420
- Fix wiki project clone address error (chujinjin). !4429 - Fix wiki project clone address error (chujinjin). !4429
- Fix serious performance bug with rendering Markdown with InlineDiffFilter. !4392
- In search results, only show notes on confidential issues that the user has access to - In search results, only show notes on confidential issues that the user has access to
v 8.8.2 v 8.8.2
......
...@@ -8,15 +8,19 @@ module Banzai ...@@ -8,15 +8,19 @@ module Banzai
next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS) next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS)
content = node.to_html content = node.to_html
content = content.gsub(/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/, '<span class="idiff left right deletion">\1\2</span>') html_content = inline_diff_filter(content)
content = content.gsub(/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/, '<span class="idiff left right addition">\1\2</span>')
next if html == content next if content == html_content
node.replace(content) node.replace(html_content)
end end
doc doc
end end
def inline_diff_filter(text)
html_content = text.gsub(/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/, '<span class="idiff left right deletion">\1\2</span>')
html_content.gsub(/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/, '<span class="idiff left right addition">\1\2</span>')
end
end end
end end
end end
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