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
Jérome Perrin
gitlab-ce
Commits
88e3ce30
Commit
88e3ce30
authored
Nov 19, 2017
by
Stan Hu
Committed by
Francisco Lopez
Dec 01, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize API /groups/:id/projects by preloading associations
Closes #40308
parent
c594659f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
changelogs/unreleased/sh-optimize-groups-api.yml
changelogs/unreleased/sh-optimize-groups-api.yml
+5
-0
lib/api/groups.rb
lib/api/groups.rb
+1
-0
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+14
-0
No files found.
changelogs/unreleased/sh-optimize-groups-api.yml
0 → 100644
View file @
88e3ce30
---
title
:
Optimize API /groups/:id/projects by preloading fork_networks table
merge_request
:
author
:
type
:
performance
lib/api/groups.rb
View file @
88e3ce30
...
...
@@ -172,6 +172,7 @@ module API
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
)
projects
=
reorder_projects
(
projects
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
present
paginate
(
projects
),
with:
entity
,
current_user:
current_user
...
...
spec/requests/api/groups_spec.rb
View file @
88e3ce30
...
...
@@ -401,6 +401,20 @@ describe API::Groups do
expect
(
response
).
to
have_gitlab_http_status
(
404
)
end
it
'avoids N+1 queries'
do
get
api
(
"/groups/
#{
group1
.
id
}
/projects"
,
admin
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
get
api
(
"/groups/
#{
group1
.
id
}
/projects"
,
admin
)
end
.
count
create
(
:project
,
namespace:
group1
)
expect
do
get
api
(
"/groups/
#{
group1
.
id
}
/projects"
,
admin
)
end
.
not_to
exceed_query_limit
(
control_count
)
end
end
context
'when using group path in URL'
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