Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
26865038
Commit
26865038
authored
Aug 21, 2020
by
Dmitry Gruzd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize markdown rendering in search results
parent
c2d68b94
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
30 additions
and
8 deletions
+30
-8
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+5
-4
app/views/search/results/_issue.html.haml
app/views/search/results/_issue.html.haml
+1
-1
app/views/search/results/_merge_request.html.haml
app/views/search/results/_merge_request.html.haml
+1
-1
app/views/search/results/_milestone.html.haml
app/views/search/results/_milestone.html.haml
+1
-1
app/views/search/results/_note.html.haml
app/views/search/results/_note.html.haml
+1
-1
changelogs/unreleased/233301-search-markdown-rendering-queries.yml
...s/unreleased/233301-search-markdown-rendering-queries.yml
+5
-0
spec/helpers/search_helper_spec.rb
spec/helpers/search_helper_spec.rb
+16
-0
No files found.
app/helpers/search_helper.rb
View file @
26865038
...
...
@@ -250,15 +250,16 @@ module SearchHelper
# Sanitize a HTML field for search display. Most tags are stripped out and the
# maximum length is set to 200 characters.
def
search_md_sanitize
(
object
,
field
)
html
=
markdown_field
(
object
,
field
)
html
=
Truncato
.
truncate
(
html
,
def
search_md_sanitize
(
source
)
source
=
Truncato
.
truncate
(
source
,
count_tags:
false
,
count_tail:
false
,
max_length:
200
)
html
=
markdown
(
source
)
# Truncato's filtered_tags and filtered_attributes are not quite the same
sanitize
(
html
,
tags:
%w(a p ol ul li pre code)
)
end
...
...
app/views/search/results/_issue.html.haml
View file @
26865038
...
...
@@ -8,6 +8,6 @@
.float-right
##{issue.iid}
-
if
issue
.
description
.
present?
.description.term
=
search_md_sanitize
(
issue
,
:
description
)
=
search_md_sanitize
(
issue
.
description
)
%span
.light
#{
issue
.
project
.
full_name
}
app/views/search/results/_merge_request.html.haml
View file @
26865038
...
...
@@ -9,6 +9,6 @@
.float-right
=
merge_request
.
to_reference
-
if
merge_request
.
description
.
present?
.description.term
=
search_md_sanitize
(
merge_request
,
:
description
)
=
search_md_sanitize
(
merge_request
.
description
)
%span
.light
#{
merge_request
.
project
.
full_name
}
app/views/search/results/_milestone.html.haml
View file @
26865038
...
...
@@ -5,4 +5,4 @@
-
if
milestone
.
description
.
present?
.description.term
=
search_md_sanitize
(
milestone
,
:
description
)
=
search_md_sanitize
(
milestone
.
description
)
app/views/search/results/_note.html.haml
View file @
26865038
...
...
@@ -22,4 +22,4 @@
.note-search-result
.term
=
search_md_sanitize
(
note
,
:
note
)
=
search_md_sanitize
(
note
.
note
)
changelogs/unreleased/233301-search-markdown-rendering-queries.yml
0 → 100644
View file @
26865038
---
title
:
Optimize markdown rendering in search results
merge_request
:
39833
author
:
type
:
performance
spec/helpers/search_helper_spec.rb
View file @
26865038
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
SearchHelper
do
include
MarkupHelper
# Override simple_sanitize for our testing purposes
def
simple_sanitize
(
str
)
str
...
...
@@ -228,6 +230,20 @@ RSpec.describe SearchHelper do
end
end
describe
'search_md_sanitize'
do
it
'does not do extra sql queries for partial markdown rendering'
do
@project
=
create
(
:project
)
description
=
FFaker
::
Lorem
.
characters
(
210
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
{
search_md_sanitize
(
description
)
}.
count
issues
=
create_list
(
:issue
,
4
,
project:
@project
)
description_with_issues
=
description
+
' '
+
issues
.
map
{
|
issue
|
"#
#{
issue
.
iid
}
"
}.
join
(
' '
)
expect
{
search_md_sanitize
(
description_with_issues
)
}.
not_to
exceed_all_query_limit
(
control_count
)
end
end
describe
'search_filter_link'
do
it
'renders a search filter link for the current scope'
do
@scope
=
'projects'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment