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
ce1ce820
Commit
ce1ce820
authored
Aug 21, 2017
by
Travis Miller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Resolve new N+1 by adding preloads and metadata to issues end points
parent
2531fb3b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
5 deletions
+39
-5
lib/api/entities.rb
lib/api/entities.rb
+20
-2
lib/api/issues.rb
lib/api/issues.rb
+19
-3
No files found.
lib/api/entities.rb
View file @
ce1ce820
...
@@ -320,7 +320,10 @@ module API
...
@@ -320,7 +320,10 @@ module API
end
end
class
IssueBasic
<
ProjectEntity
class
IssueBasic
<
ProjectEntity
expose
:label_names
,
as: :labels
expose
:labels
do
|
issue
,
options
|
# Avoids an N+1 query since labels are preloaded
issue
.
labels
.
map
(
&
:title
).
sort
end
expose
:milestone
,
using:
Entities
::
Milestone
expose
:milestone
,
using:
Entities
::
Milestone
expose
:assignees
,
:author
,
using:
Entities
::
UserBasic
expose
:assignees
,
:author
,
using:
Entities
::
UserBasic
...
@@ -329,7 +332,22 @@ module API
...
@@ -329,7 +332,22 @@ module API
end
end
expose
:user_notes_count
expose
:user_notes_count
expose
:upvotes
,
:downvotes
expose
:upvotes
do
|
issue
,
options
|
if
options
[
:issuable_metadata
]
# Avoids an N+1 query when metadata is included
options
[
:issuable_metadata
][
issue
.
id
].
upvotes
else
issue
.
upvotes
end
end
expose
:downvotes
do
|
issue
,
options
|
if
options
[
:issuable_metadata
]
# Avoids an N+1 query when metadata is included
options
[
:issuable_metadata
][
issue
.
id
].
downvotes
else
issue
.
downvotes
end
end
expose
:due_date
expose
:due_date
expose
:confidential
expose
:confidential
...
...
lib/api/issues.rb
View file @
ce1ce820
...
@@ -4,6 +4,8 @@ module API
...
@@ -4,6 +4,8 @@ module API
before
{
authenticate!
}
before
{
authenticate!
}
helpers
::
Gitlab
::
IssuableMetadata
helpers
do
helpers
do
def
find_issues
(
args
=
{})
def
find_issues
(
args
=
{})
args
=
params
.
merge
(
args
)
args
=
params
.
merge
(
args
)
...
@@ -13,6 +15,7 @@ module API
...
@@ -13,6 +15,7 @@ module API
args
[
:label_name
]
=
args
.
delete
(
:labels
)
args
[
:label_name
]
=
args
.
delete
(
:labels
)
issues
=
IssuesFinder
.
new
(
current_user
,
args
).
execute
issues
=
IssuesFinder
.
new
(
current_user
,
args
).
execute
.
preload
(
:assignees
,
:labels
,
:notes
)
issues
.
reorder
(
args
[
:order_by
]
=>
args
[
:sort
])
issues
.
reorder
(
args
[
:order_by
]
=>
args
[
:sort
])
end
end
...
@@ -65,7 +68,11 @@ module API
...
@@ -65,7 +68,11 @@ module API
get
do
get
do
issues
=
find_issues
issues
=
find_issues
present
paginate
(
issues
),
with:
Entities
::
IssueBasic
,
current_user:
current_user
options
=
{
with:
Entities
::
IssueBasic
,
current_user:
current_user
}
options
[
:issuable_metadata
]
=
issuable_meta_data
(
issues
,
'Issue'
)
present
paginate
(
issues
),
options
end
end
end
end
...
@@ -86,7 +93,11 @@ module API
...
@@ -86,7 +93,11 @@ module API
issues
=
find_issues
(
group_id:
group
.
id
)
issues
=
find_issues
(
group_id:
group
.
id
)
present
paginate
(
issues
),
with:
Entities
::
IssueBasic
,
current_user:
current_user
options
=
{
with:
Entities
::
IssueBasic
,
current_user:
current_user
}
options
[
:issuable_metadata
]
=
issuable_meta_data
(
issues
,
'Issue'
)
present
paginate
(
issues
),
options
end
end
end
end
...
@@ -109,7 +120,12 @@ module API
...
@@ -109,7 +120,12 @@ module API
issues
=
find_issues
(
project_id:
project
.
id
)
issues
=
find_issues
(
project_id:
project
.
id
)
present
paginate
(
issues
),
with:
Entities
::
IssueBasic
,
current_user:
current_user
,
project:
user_project
options
=
{
with:
Entities
::
IssueBasic
,
current_user:
current_user
,
project:
user_project
}
options
[
:issuable_metadata
]
=
issuable_meta_data
(
issues
,
'Issue'
)
present
paginate
(
issues
),
options
end
end
desc
'Get a single project issue'
do
desc
'Get a single project issue'
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