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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2135edc2
Commit
2135edc2
authored
Jan 21, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
1d24ec4b
10d421be
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
changelogs/unreleased/sh-preload-associations-for-group-api.yml
...logs/unreleased/sh-preload-associations-for-group-api.yml
+5
-0
lib/api/entities.rb
lib/api/entities.rb
+6
-2
spec/requests/api/groups_spec.rb
spec/requests/api/groups_spec.rb
+14
-0
No files found.
changelogs/unreleased/sh-preload-associations-for-group-api.yml
0 → 100644
View file @
2135edc2
---
title
:
Eliminate N+1 queries in /api/groups/:id
merge_request
:
24513
author
:
type
:
performance
lib/api/entities.rb
View file @
2135edc2
...
...
@@ -344,19 +344,23 @@ module API
class
GroupDetail
<
Group
expose
:projects
,
using:
Entities
::
Project
do
|
group
,
options
|
GroupProjectsFinder
.
new
(
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
options
[
:current_user
],
options:
{
only_owned:
true
}
).
execute
Entities
::
Project
.
prepare_relation
(
projects
)
end
expose
:shared_projects
,
using:
Entities
::
Project
do
|
group
,
options
|
GroupProjectsFinder
.
new
(
projects
=
GroupProjectsFinder
.
new
(
group:
group
,
current_user:
options
[
:current_user
],
options:
{
only_shared:
true
}
).
execute
Entities
::
Project
.
prepare_relation
(
projects
)
end
end
...
...
spec/requests/api/groups_spec.rb
View file @
2135edc2
...
...
@@ -396,6 +396,20 @@ describe API::Groups do
expect
(
response_project_ids
(
json_response
,
'shared_projects'
))
.
to
contain_exactly
(
projects
[
:public
].
id
,
projects
[
:internal
].
id
)
end
it
'avoids N+1 queries'
do
get
api
(
"/groups/
#{
group1
.
id
}
"
,
admin
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
do
get
api
(
"/groups/
#{
group1
.
id
}
"
,
admin
)
end
.
count
create
(
:project
,
namespace:
group1
)
expect
do
get
api
(
"/groups/
#{
group1
.
id
}
"
,
admin
)
end
.
not_to
exceed_query_limit
(
control_count
)
end
end
context
"when authenticated as admin"
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