diff options
author | Sean McGivern <sean@gitlab.com> | 2019-05-22 17:30:10 +0300 |
---|---|---|
committer | Sean McGivern <sean@gitlab.com> | 2019-05-22 18:56:12 +0300 |
commit | f9f9147290b5bc315e595e059c851593c1fc466f (patch) | |
tree | 40ea181966c7ed2b1451bd89ab280361c79596fd /app/helpers | |
parent | bc4a18ecb9e85a5ee51541ed25b2cb9c4a2768b5 (diff) |
Fix page_description helper performance
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 'app/helpers')
-rw-r--r-- | app/helpers/page_layout_helper.rb | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/app/helpers/page_layout_helper.rb b/app/helpers/page_layout_helper.rb index 5038dcf9746..ec1d8577f36 100644 --- a/app/helpers/page_layout_helper.rb +++ b/app/helpers/page_layout_helper.rb @@ -1,3 +1,4 @@ +# coding: utf-8 # frozen_string_literal: true module PageLayoutHelper @@ -36,7 +37,7 @@ module PageLayoutHelper if description.present? @page_description = description.squish elsif @page_description.present? - sanitize(@page_description, tags: []).truncate_words(30) + sanitize(@page_description.truncate_words(30), tags: []) end end |