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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
94af78ac
Commit
94af78ac
authored
Feb 05, 2016
by
Valery Sizov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Faster snippet search
parent
569c4672
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
29 deletions
+30
-29
CHANGELOG
CHANGELOG
+1
-0
app/helpers/snippets_helper.rb
app/helpers/snippets_helper.rb
+3
-3
app/views/search/results/_snippet_blob.html.haml
app/views/search/results/_snippet_blob.html.haml
+24
-20
lib/gitlab/snippet_search_results.rb
lib/gitlab/snippet_search_results.rb
+2
-6
No files found.
CHANGELOG
View file @
94af78ac
...
@@ -34,6 +34,7 @@ v 8.5.0 (unreleased)
...
@@ -34,6 +34,7 @@ v 8.5.0 (unreleased)
- Add sort dropdown to dashboard projects page
- Add sort dropdown to dashboard projects page
- Hide remove source branch button when the MR is merged but new commits are pushed (Zeger-Jan van de Weg)
- Hide remove source branch button when the MR is merged but new commits are pushed (Zeger-Jan van de Weg)
- In seach autocomplete show only groups and projects you are member of
- In seach autocomplete show only groups and projects you are member of
- Faster snippet search
v 8.4.3
v 8.4.3
- Increase lfs_objects size column to 8-byte integer to allow files larger
- Increase lfs_objects size column to 8-byte integer to allow files larger
...
...
app/helpers/snippets_helper.rb
View file @
94af78ac
...
@@ -33,7 +33,7 @@ module SnippetsHelper
...
@@ -33,7 +33,7 @@ module SnippetsHelper
# surrounding code.
# surrounding code.
#
#
# @returns Array, unique and sorted.
# @returns Array, unique and sorted.
def
matching_lines
(
lined_content
,
surrounding_lines
)
def
matching_lines
(
lined_content
,
surrounding_lines
,
query
)
used_lines
=
[]
used_lines
=
[]
lined_content
.
each_with_index
do
|
line
,
line_number
|
lined_content
.
each_with_index
do
|
line
,
line_number
|
used_lines
.
concat
bounded_line_numbers
(
used_lines
.
concat
bounded_line_numbers
(
...
@@ -51,9 +51,9 @@ module SnippetsHelper
...
@@ -51,9 +51,9 @@ module SnippetsHelper
# surrounding_lines() worth of unmatching lines.
# surrounding_lines() worth of unmatching lines.
#
#
# @returns a hash with {snippet_object, snippet_chunks:{data,start_line}}
# @returns a hash with {snippet_object, snippet_chunks:{data,start_line}}
def
chunk_snippet
(
snippet
,
surrounding_lines
=
3
)
def
chunk_snippet
(
snippet
,
query
,
surrounding_lines
=
3
)
lined_content
=
snippet
.
content
.
split
(
"
\n
"
)
lined_content
=
snippet
.
content
.
split
(
"
\n
"
)
used_lines
=
matching_lines
(
lined_content
,
surrounding_lines
)
used_lines
=
matching_lines
(
lined_content
,
surrounding_lines
,
query
)
snippet_chunk
=
[]
snippet_chunk
=
[]
snippet_chunks
=
[]
snippet_chunks
=
[]
...
...
app/views/search/results/_snippet_blob.html.haml
View file @
94af78ac
-
snippet_blob
=
chunk_snippet
(
snippet_blob
,
@search_term
)
-
snippet
=
snippet_blob
[
:snippet_object
]
-
snippet_chunks
=
snippet_blob
[
:snippet_chunks
]
.search-result-row
.search-result-row
%span
%span
=
snippet
_blob
[
:snippet_object
]
.
title
=
snippet
.
title
by
by
=
link_to
user_snippets_path
(
snippet
_blob
[
:snippet_object
]
.
author
)
do
=
link_to
user_snippets_path
(
snippet
.
author
)
do
=
image_tag
avatar_icon
(
snippet
_blob
[
:snippet_object
]
.
author_email
),
class:
"avatar avatar-inline s16"
,
alt:
''
=
image_tag
avatar_icon
(
snippet
.
author_email
),
class:
"avatar avatar-inline s16"
,
alt:
''
=
snippet
_blob
[
:snippet_object
]
.
author_name
=
snippet
.
author_name
%span
.light
#{
time_ago_with_tooltip
(
snippet
_blob
[
:snippet_object
]
.
created_at
)
}
%span
.light
#{
time_ago_with_tooltip
(
snippet
.
created_at
)
}
%h4
.snippet-title
%h4
.snippet-title
-
snippet_path
=
reliable_snippet_path
(
snippet
_blob
[
:snippet_object
]
)
-
snippet_path
=
reliable_snippet_path
(
snippet
)
=
link_to
snippet_path
do
=
link_to
snippet_path
do
.file-holder
.file-holder
.file-title
.file-title
%i
.fa.fa-file
%i
.fa.fa-file
%strong
=
snippet
_blob
[
:snippet_object
]
.
file_name
%strong
=
snippet
.
file_name
-
if
markup?
(
snippet
_blob
[
:snippet_object
]
.
file_name
)
-
if
markup?
(
snippet
.
file_name
)
.file-content.wiki
.file-content.wiki
-
snippet_
blob
[
:snippet_chunks
].
each
do
|
snippet
|
-
snippet_
chunks
.
each
do
|
chunk
|
-
unless
snippet
[
:data
].
empty?
-
unless
chunk
[
:data
].
empty?
=
render_markup
(
snippet
_blob
[
:snippet_object
].
file_name
,
snippet
[
:data
])
=
render_markup
(
snippet
.
file_name
,
chunk
[
:data
])
-
else
-
else
.file-content.code
.file-content.code
.nothing-here-block
Empty file
.nothing-here-block
Empty file
-
else
-
else
.file-content.code.js-syntax-highlight
.file-content.code.js-syntax-highlight
.line-numbers
.line-numbers
-
snippet_
blob
[
:snippet_chunks
].
each
do
|
snippet
|
-
snippet_
chunks
.
each
do
|
chunk
|
-
unless
snippet
[
:data
].
empty?
-
unless
chunk
[
:data
].
empty?
-
snippet
[
:data
].
lines
.
to_a
.
size
.
times
do
|
index
|
-
chunk
[
:data
].
lines
.
to_a
.
size
.
times
do
|
index
|
-
offset
=
defined?
(
snippet
[
:start_line
])
?
snippet
[
:start_line
]
:
1
-
offset
=
defined?
(
chunk
[
:start_line
])
?
chunk
[
:start_line
]
:
1
-
i
=
index
+
offset
-
i
=
index
+
offset
=
link_to
snippet_path
+
"#L
#{
i
}
"
,
id:
"L
#{
i
}
"
,
rel:
"#L
#{
i
}
"
,
class:
"diff-line-num"
do
=
link_to
snippet_path
+
"#L
#{
i
}
"
,
id:
"L
#{
i
}
"
,
rel:
"#L
#{
i
}
"
,
class:
"diff-line-num"
do
%i
.fa.fa-link
%i
.fa.fa-link
=
i
=
i
-
unless
snippet
==
snippet_
blob
[
:snippet_chunks
]
.
last
-
unless
snippet
==
snippet_
chunks
.
last
%a
.diff-line-num
%a
.diff-line-num
=
"."
=
"."
%pre
.code
%pre
.code
%code
%code
-
snippet_
blob
[
:snippet_chunks
].
each
do
|
snippet
|
-
snippet_
chunks
.
each
do
|
chunk
|
-
unless
snippet
[
:data
].
empty?
-
unless
chunk
[
:data
].
empty?
=
snippet
[
:data
]
=
chunk
[
:data
]
-
unless
snippet
==
snippet_blob
[
:snippet_chunks
]
.
last
-
unless
chunk
==
snippet_chunks
.
last
%a
%a
=
"..."
=
"..."
-
else
-
else
...
...
lib/gitlab/snippet_search_results.rb
View file @
94af78ac
...
@@ -14,7 +14,7 @@ module Gitlab
...
@@ -14,7 +14,7 @@ module Gitlab
when
'snippet_titles'
when
'snippet_titles'
Kaminari
.
paginate_array
(
snippet_titles
).
page
(
page
).
per
(
per_page
)
Kaminari
.
paginate_array
(
snippet_titles
).
page
(
page
).
per
(
per_page
)
when
'snippet_blobs'
when
'snippet_blobs'
Kaminari
.
paginate_array
(
snippet_blobs
)
.
page
(
page
).
per
(
per_page
)
snippet_blobs
.
page
(
page
).
per
(
per_page
)
else
else
super
super
end
end
...
@@ -39,11 +39,7 @@ module Gitlab
...
@@ -39,11 +39,7 @@ module Gitlab
end
end
def
snippet_blobs
def
snippet_blobs
search
=
Snippet
.
where
(
id:
limit_snippet_ids
).
search_code
(
query
)
Snippet
.
where
(
id:
limit_snippet_ids
).
search_code
(
query
).
order
(
'updated_at DESC'
)
search
=
search
.
order
(
'updated_at DESC'
).
to_a
snippets
=
[]
search
.
each
{
|
e
|
snippets
<<
chunk_snippet
(
e
)
}
snippets
end
end
def
default_scope
def
default_scope
...
...
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