From 990d263dbca030439e3cd6e5e1dd1a0006f16154 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Tue, 24 Jul 2018 10:58:53 -0700 Subject: Fix slow Markdown rendering 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. --- changelogs/unreleased/sh-revert-markdown-changes.yml | 5 +++++ lib/banzai/filter/sanitization_filter.rb | 17 ++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 changelogs/unreleased/sh-revert-markdown-changes.yml 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: (?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) -- cgit v1.2.1