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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
42fde69d
Commit
42fde69d
authored
Mar 01, 2016
by
Yorick Peterse
Committed by
Robert Speicher
Mar 11, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Gitlab::SnippetSearchResults
This removes the need for plucking snippet IDs into memory.
parent
01354296
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
7 deletions
+33
-7
app/services/search/snippet_service.rb
app/services/search/snippet_service.rb
+3
-2
lib/gitlab/snippet_search_results.rb
lib/gitlab/snippet_search_results.rb
+5
-5
spec/lib/gitlab/snippet_search_results_spec.rb
spec/lib/gitlab/snippet_search_results_spec.rb
+25
-0
No files found.
app/services/search/snippet_service.rb
View file @
42fde69d
...
@@ -7,8 +7,9 @@ module Search
...
@@ -7,8 +7,9 @@ module Search
end
end
def
execute
def
execute
snippet_ids
=
Snippet
.
accessible_to
(
current_user
).
pluck
(
:id
)
snippets
=
Snippet
.
accessible_to
(
current_user
)
Gitlab
::
SnippetSearchResults
.
new
(
snippet_ids
,
params
[
:search
])
Gitlab
::
SnippetSearchResults
.
new
(
snippets
,
params
[
:search
])
end
end
end
end
end
end
lib/gitlab/snippet_search_results.rb
View file @
42fde69d
...
@@ -2,10 +2,10 @@ module Gitlab
...
@@ -2,10 +2,10 @@ module Gitlab
class
SnippetSearchResults
<
SearchResults
class
SnippetSearchResults
<
SearchResults
include
SnippetsHelper
include
SnippetsHelper
attr_reader
:limit_snippet
_id
s
attr_reader
:limit_snippets
def
initialize
(
limit_snippet
_id
s
,
query
)
def
initialize
(
limit_snippets
,
query
)
@limit_snippet
_ids
=
limit_snippet_id
s
@limit_snippet
s
=
limit_snippet
s
@query
=
query
@query
=
query
end
end
...
@@ -35,11 +35,11 @@ module Gitlab
...
@@ -35,11 +35,11 @@ module Gitlab
private
private
def
snippet_titles
def
snippet_titles
Snippet
.
where
(
id:
limit_snippet_ids
)
.
search
(
query
).
order
(
'updated_at DESC'
)
limit_snippets
.
search
(
query
).
order
(
'updated_at DESC'
)
end
end
def
snippet_blobs
def
snippet_blobs
Snippet
.
where
(
id:
limit_snippet_ids
)
.
search_code
(
query
).
order
(
'updated_at DESC'
)
limit_snippets
.
search_code
(
query
).
order
(
'updated_at DESC'
)
end
end
def
default_scope
def
default_scope
...
...
spec/lib/gitlab/snippet_search_results_spec.rb
0 → 100644
View file @
42fde69d
require
'spec_helper'
describe
Gitlab
::
SnippetSearchResults
do
let!
(
:snippet
)
{
create
(
:snippet
,
content:
'foo'
,
file_name:
'foo'
)
}
let
(
:results
)
{
described_class
.
new
(
Snippet
.
all
,
'foo'
)
}
describe
'#total_count'
do
it
'returns the total amount of search hits'
do
expect
(
results
.
total_count
).
to
eq
(
2
)
end
end
describe
'#snippet_titles_count'
do
it
'returns the amount of matched snippet titles'
do
expect
(
results
.
snippet_titles_count
).
to
eq
(
1
)
end
end
describe
'#snippet_blobs_count'
do
it
'returns the amount of matched snippet blobs'
do
expect
(
results
.
snippet_blobs_count
).
to
eq
(
1
)
end
end
end
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