Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
42fde69d
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
42fde69d
编写于
3月 01, 2016
作者:
Y
Yorick Peterse
提交者:
Robert Speicher
3月 11, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor Gitlab::SnippetSearchResults
This removes the need for plucking snippet IDs into memory.
上级
01354296
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
33 addition
and
7 deletion
+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
未找到文件。
app/services/search/snippet_service.rb
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录