diff options
author | Sean McGivern <sean@gitlab.com> | 2019-05-22 15:30:10 +0100 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-05-22 16:56:12 +0100 |
commit | f9f9147290b5bc315e595e059c851593c1fc466f (patch) | |
tree | 40ea181966c7ed2b1451bd89ab280361c79596fd /spec | |
parent | bc4a18ecb9e85a5ee51541ed25b2cb9c4a2768b5 (diff) | |
download | gitlab-ce-f9f9147290b5bc315e595e059c851593c1fc466f.tar.gz |
Fix page_description helper performance62116-performance-issue-502-errors-on-rendering-of-issues-with-heavy-markdown-contents
This helper is used for extracting part of the issue / MR / whatever
description for use in the description meta tag:
1. To do that, we look at the source of the Markdown description.
2. We then strip out all HTML tags.
3. And then take the first 30 words.
Doing that can be really slow - especially as Markdown is supposed to be
treated as plain text. There are many better ways to do this, but the
immediate performance fix is to swap steps 2 and 3. This does mean that
the description may be less than 30 words (or even empty), but it is
much faster when the description is very long.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/helpers/page_layout_helper_spec.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/spec/helpers/page_layout_helper_spec.rb b/spec/helpers/page_layout_helper_spec.rb index cf98eed27f1..bf50763d06f 100644 --- a/spec/helpers/page_layout_helper_spec.rb +++ b/spec/helpers/page_layout_helper_spec.rb @@ -38,6 +38,14 @@ describe PageLayoutHelper do expect(helper.page_description).to eq 'Bold Header' end + + it 'truncates before sanitizing' do + helper.page_description('<b>Bold</b> <img> <img> <img> <h1>Header</h1> ' * 10) + + # 12 words because <img> was counted as a word + expect(helper.page_description) + .to eq('Bold Header Bold Header Bold Header Bold Header Bold Header Bold Header...') + end end describe 'page_image' do |