Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
a2babf32
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,发现更多精彩内容 >>
提交
a2babf32
编写于
11月 24, 2017
作者:
F
Francisco Lopez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
More preloading improvement and added batch count services
上级
dd562ae7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
88 addition
and
7 deletion
+88
-7
app/services/base_count_service.rb
app/services/base_count_service.rb
+2
-2
app/services/projects/batch_count_service.rb
app/services/projects/batch_count_service.rb
+35
-0
app/services/projects/batch_forks_count_service.rb
app/services/projects/batch_forks_count_service.rb
+14
-0
app/services/projects/batch_open_issues_count_service.rb
app/services/projects/batch_open_issues_count_service.rb
+15
-0
app/services/projects/count_service.rb
app/services/projects/count_service.rb
+2
-0
lib/api/groups.rb
lib/api/groups.rb
+20
-5
未找到文件。
app/services/base_count_service.rb
浏览文件 @
a2babf32
...
...
@@ -12,8 +12,8 @@ class BaseCountService
Rails
.
cache
.
fetch
(
cache_key
,
cache_options
)
{
uncached_count
}.
to_i
end
def
refresh_cache
Rails
.
cache
.
write
(
cache_key
,
uncached_count
,
raw:
raw?
)
def
refresh_cache
(
&
block
)
Rails
.
cache
.
write
(
cache_key
,
block_given?
?
yield
:
uncached_count
,
raw:
raw?
)
end
def
uncached_count
...
...
app/services/projects/batch_count_service.rb
0 → 100644
浏览文件 @
a2babf32
module
Projects
class
BatchCountService
def
initialize
(
projects
)
@projects
=
projects
end
def
count
@projects
.
map
do
|
project
|
[
project
.
id
,
current_count_service
(
project
).
count
]
end
.
to_h
end
def
refresh_cache
@projects
.
each
do
|
project
|
current_count_service
(
project
).
refresh_cache
{
global_count
[
project
.
id
].
to_i
}
end
end
def
current_count_service
(
project
)
if
defined?
@service
@service
.
project
=
project
else
count_service
.
new
(
project
)
end
end
def
global_count
(
project
)
raise
NotImplementedError
,
'global_count must be implemented and return an hash indexed by the project id'
end
def
count_service
raise
NotImplementedError
,
'count_service must be implemented and return a Projects::CountService object'
end
end
end
app/services/projects/batch_forks_count_service.rb
0 → 100644
浏览文件 @
a2babf32
module
Projects
# Service class for getting and caching the number of forks of several projects
class
BatchForksCountService
<
Projects
::
BatchCountService
def
global_count
@global_count
||=
ForkedProjectLink
.
where
(
forked_from_project:
@projects
.
map
(
&
:id
))
.
group
(
:forked_from_project_id
)
.
count
end
def
count_service
::
Projects
::
ForksCountService
end
end
end
app/services/projects/batch_open_issues_count_service.rb
0 → 100644
浏览文件 @
a2babf32
module
Projects
# Service class for getting and caching the number of forks of several projects
class
BatchOpenIssuesCountService
<
Projects
::
BatchCountService
def
global_count
@global_count
||=
Issue
.
opened
.
public_only
.
where
(
project:
@projects
.
map
(
&
:id
))
.
group
(
:project_id
)
.
count
end
def
count_service
::
Projects
::
OpenIssuesCountService
end
end
end
app/services/projects/count_service.rb
浏览文件 @
a2babf32
...
...
@@ -7,6 +7,8 @@ module Projects
# all caches.
VERSION
=
1
attr_accessor
:project
def
initialize
(
project
)
@project
=
project
end
...
...
lib/api/groups.rb
浏览文件 @
a2babf32
...
...
@@ -52,6 +52,24 @@ module API
groups
end
def
find_group_projects
(
params
)
group
=
find_group!
(
params
[
:id
])
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
current_user
,
params:
project_finder_params
).
execute
projects
=
projects
.
preload
(
:project_feature
,
:route
,
:group
)
.
preload
(
namespace:
[
:route
,
:owner
],
tags: :taggings
,
project_group_links: :group
,
fork_network: :root_project
,
forked_project_link: :forked_from_project
,
forked_from_project:
[
:route
,
:forks
,
namespace: :route
,
tags: :taggings
])
projects
=
reorder_projects
(
projects
)
paginated_projects
=
paginate
(
projects
)
projects_with_fork
=
paginated_projects
+
paginated_projects
.
map
(
&
:forked_from_project
).
compact
::
Projects
::
BatchForksCountService
.
new
(
projects_with_fork
).
refresh_cache
::
Projects
::
BatchOpenIssuesCountService
.
new
(
paginated_projects
).
refresh_cache
paginated_projects
end
def
present_groups
(
params
,
groups
)
options
=
{
with:
Entities
::
Group
,
...
...
@@ -170,12 +188,9 @@ module API
use
:pagination
end
get
":id/projects"
do
group
=
find_group!
(
params
[
:id
])
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
current_user
,
params:
project_finder_params
).
execute
projects
=
projects
.
preload
(
:fork_network
,
:forked_project_link
,
:project_feature
,
:project_group_links
,
:tags
,
:taggings
,
:group
,
:namespace
,
:route
)
projects
=
reorder_projects
(
projects
)
projects
=
find_group_projects
(
params
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
present
p
aginate
(
projects
)
,
with:
entity
,
current_user:
current_user
present
p
rojects
,
with:
entity
,
current_user:
current_user
end
desc
'Get a list of subgroups in this group.'
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录