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
Boxiang Sun
gitlab-ce
Commits
a2babf32
Commit
a2babf32
authored
Nov 24, 2017
by
Francisco Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More preloading improvement and added batch count services
parent
dd562ae7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
7 deletions
+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
No files found.
app/services/base_count_service.rb
View file @
a2babf32
...
@@ -12,8 +12,8 @@ class BaseCountService
...
@@ -12,8 +12,8 @@ class BaseCountService
Rails
.
cache
.
fetch
(
cache_key
,
cache_options
)
{
uncached_count
}.
to_i
Rails
.
cache
.
fetch
(
cache_key
,
cache_options
)
{
uncached_count
}.
to_i
end
end
def
refresh_cache
def
refresh_cache
(
&
block
)
Rails
.
cache
.
write
(
cache_key
,
uncached_count
,
raw:
raw?
)
Rails
.
cache
.
write
(
cache_key
,
block_given?
?
yield
:
uncached_count
,
raw:
raw?
)
end
end
def
uncached_count
def
uncached_count
...
...
app/services/projects/batch_count_service.rb
0 → 100644
View file @
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
View file @
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
View file @
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
View file @
a2babf32
...
@@ -7,6 +7,8 @@ module Projects
...
@@ -7,6 +7,8 @@ module Projects
# all caches.
# all caches.
VERSION
=
1
VERSION
=
1
attr_accessor
:project
def
initialize
(
project
)
def
initialize
(
project
)
@project
=
project
@project
=
project
end
end
...
...
lib/api/groups.rb
View file @
a2babf32
...
@@ -52,6 +52,24 @@ module API
...
@@ -52,6 +52,24 @@ module API
groups
groups
end
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
)
def
present_groups
(
params
,
groups
)
options
=
{
options
=
{
with:
Entities
::
Group
,
with:
Entities
::
Group
,
...
@@ -170,12 +188,9 @@ module API
...
@@ -170,12 +188,9 @@ module API
use
:pagination
use
:pagination
end
end
get
":id/projects"
do
get
":id/projects"
do
group
=
find_group!
(
params
[
:id
])
projects
=
find_group_projects
(
params
)
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
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
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
end
desc
'Get a list of subgroups in this group.'
do
desc
'Get a list of subgroups in this group.'
do
...
...
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