summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-07-24 10:58:53 -0700
committerStan Hu <stanhu@gmail.com>2018-07-24 11:20:03 -0700
commit990d263dbca030439e3cd6e5e1dd1a0006f16154 (patch)
treecb47aea6ad3126aaecd60b9638913bc023994764
parentc06e2ac888fb5180cdf133df89d03b99eceafa0d (diff)
downloadgitlab-ce-sh-revert-markdown-changes.tar.gz
Fix slow Markdown renderingsh-revert-markdown-changes
The sanitize transformers were being duplicated each time the Markdown renderer was called, leading to expontential growth in rendering times. Revert "Use strong_memoize to customize the SanitizationFilter whitelist" This reverts commit d699362a0931427354a40246b72747837ad85fcb.
-rw-r--r--changelogs/unreleased/sh-revert-markdown-changes.yml5
-rw-r--r--lib/banzai/filter/sanitization_filter.rb17
2 files changed, 17 insertions, 5 deletions
diff --git a/changelogs/unreleased/sh-revert-markdown-changes.yml b/changelogs/unreleased/sh-revert-markdown-changes.yml
new file mode 100644
index 00000000000..72540f710a1
--- /dev/null
+++ b/changelogs/unreleased/sh-revert-markdown-changes.yml
@@ -0,0 +1,5 @@
+---
+title: Fix slow Markdown rendering
+merge_request: 20820
+author:
+type: performance
diff --git a/lib/banzai/filter/sanitization_filter.rb b/lib/banzai/filter/sanitization_filter.rb
index 80b9d3d045f..80a5394dc12 100644
--- a/lib/banzai/filter/sanitization_filter.rb
+++ b/lib/banzai/filter/sanitization_filter.rb
@@ -6,20 +6,27 @@ module Banzai
#
# Extends HTML::Pipeline::SanitizationFilter with a custom whitelist.
class SanitizationFilter < HTML::Pipeline::SanitizationFilter
- include Gitlab::Utils::StrongMemoize
-
UNSAFE_PROTOCOLS = %w(data javascript vbscript).freeze
TABLE_ALIGNMENT_PATTERN = /text-align: (?<alignment>center|left|right)/
def whitelist
- strong_memoize(:whitelist) do
- customize_whitelist(super.dup)
- end
+ whitelist = super.dup
+
+ customize_whitelist(whitelist)
+
+ whitelist
end
private
+ def customized?(transformers)
+ transformers.last.source_location[0] == __FILE__
+ end
+
def customize_whitelist(whitelist)
+ # Only push these customizations once
+ return if customized?(whitelist[:transformers])
+
# Allow table alignment; we whitelist specific text-align values in a
# transformer below
whitelist[:attributes]['th'] = %w(style)