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
cda2c5e7
Commit
cda2c5e7
authored
May 14, 2018
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only preload member records for the relevant projects/groups/user in projects API
parent
62d96d88
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
16 deletions
+26
-16
changelogs/unreleased/dm-api-projects-members-preload.yml
changelogs/unreleased/dm-api-projects-members-preload.yml
+6
-0
lib/api/entities.rb
lib/api/entities.rb
+20
-9
lib/api/projects.rb
lib/api/projects.rb
+0
-7
No files found.
changelogs/unreleased/dm-api-projects-members-preload.yml
0 → 100644
View file @
cda2c5e7
---
title
:
Only preload member records for the relevant projects/groups/user in projects
API
merge_request
:
author
:
type
:
performance
lib/api/entities.rb
View file @
cda2c5e7
...
...
@@ -832,8 +832,8 @@ module API
class
ProjectWithAccess
<
Project
expose
:permissions
do
expose
:project_access
,
using:
Entities
::
ProjectAccess
do
|
project
,
options
|
if
options
.
key?
(
:project_members
)
(
options
[
:project_members
]
||
[])
.
find
{
|
member
|
member
.
source_id
==
project
.
id
}
if
options
[
:project_members
]
options
[
:project_members
]
.
find
{
|
member
|
member
.
source_id
==
project
.
id
}
else
project
.
project_member
(
options
[
:current_user
])
end
...
...
@@ -841,8 +841,8 @@ module API
expose
:group_access
,
using:
Entities
::
GroupAccess
do
|
project
,
options
|
if
project
.
group
if
options
.
key?
(
:group_members
)
(
options
[
:group_members
]
||
[])
.
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
if
options
[
:group_members
]
options
[
:group_members
]
.
find
{
|
member
|
member
.
source_id
==
project
.
namespace_id
}
else
project
.
group
.
group_member
(
options
[
:current_user
])
end
...
...
@@ -853,13 +853,24 @@ module API
def
self
.
preload_relation
(
projects_relation
,
options
=
{})
relation
=
super
(
projects_relation
,
options
)
unless
options
.
key?
(
:group_members
)
relation
=
relation
.
preload
(
group:
[
group_members:
[
:source
,
user:
[
notification_settings: :source
]]])
# MySQL doesn't support LIMIT inside an IN subquery
if
Gitlab
::
Database
.
mysql?
project_ids
=
relation
.
pluck
(
'projects.id'
)
namespace_ids
=
relation
.
pluck
(
:namespace_id
)
else
project_ids
=
relation
.
select
(
'projects.id'
)
namespace_ids
=
relation
.
select
(
:namespace_id
)
end
unless
options
.
key?
(
:project_members
)
relation
=
relation
.
preload
(
project_members:
[
:source
,
user:
[
notification_settings: :source
]])
end
options
[
:project_members
]
=
options
[
:current_user
]
.
project_members
.
where
(
source_id:
project_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
options
[
:group_members
]
=
options
[
:current_user
]
.
group_members
.
where
(
source_id:
namespace_ids
)
.
preload
(
:source
,
user:
[
notification_settings: :source
])
relation
end
...
...
lib/api/projects.rb
View file @
cda2c5e7
...
...
@@ -58,16 +58,9 @@ module API
projects
=
paginate
(
projects
)
projects
,
options
=
with_custom_attributes
(
projects
,
options
)
if
current_user
project_members
=
current_user
.
project_members
.
preload
(
:source
,
user:
[
notification_settings: :source
])
group_members
=
current_user
.
group_members
.
preload
(
:source
,
user:
[
notification_settings: :source
])
end
options
=
options
.
reverse_merge
(
with:
current_user
?
Entities
::
ProjectWithAccess
:
Entities
::
BasicProjectDetails
,
statistics:
params
[
:statistics
],
project_members:
project_members
,
group_members:
group_members
,
current_user:
current_user
)
options
[
:with
]
=
Entities
::
BasicProjectDetails
if
params
[
:simple
]
...
...
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