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
70a0a41c
Commit
70a0a41c
authored
Jul 22, 2020
by
Igor Drozdov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix N+1 for project/:id/issues API endpoint
Preload milestones and closed_by users
parent
f4b8fb60
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
2 deletions
+14
-2
app/models/issue.rb
app/models/issue.rb
+5
-1
changelogs/unreleased/id-fix-n1-for-issues-api.yml
changelogs/unreleased/id-fix-n1-for-issues-api.yml
+5
-0
spec/requests/api/issues/get_project_issues_spec.rb
spec/requests/api/issues/get_project_issues_spec.rb
+4
-1
No files found.
app/models/issue.rb
View file @
70a0a41c
...
...
@@ -87,11 +87,15 @@ class Issue < ApplicationRecord
scope
:order_created_at_desc
,
->
{
reorder
(
created_at: :desc
)
}
scope
:preload_associated_models
,
->
{
preload
(
:assignees
,
:labels
,
project: :namespace
)
}
scope
:with_api_entity_associations
,
->
{
preload
(
:timelogs
,
:assignees
,
:author
,
:notes
,
:labels
,
project:
[
:route
,
{
namespace: :route
}]
)
}
scope
:with_label_attributes
,
->
(
label_attributes
)
{
joins
(
:labels
).
where
(
labels:
label_attributes
)
}
scope
:with_alert_management_alerts
,
->
{
joins
(
:alert_management_alert
)
}
scope
:with_prometheus_alert_events
,
->
{
joins
(
:issues_prometheus_alert_events
)
}
scope
:with_self_managed_prometheus_alert_events
,
->
{
joins
(
:issues_self_managed_prometheus_alert_events
)
}
scope
:with_api_entity_associations
,
->
{
preload
(
:timelogs
,
:closed_by
,
:assignees
,
:author
,
:notes
,
:labels
,
milestone:
{
project:
[
:route
,
{
namespace: :route
}]
},
project:
[
:route
,
{
namespace: :route
}])
}
scope
:public_only
,
->
{
where
(
confidential:
false
)
}
scope
:confidential_only
,
->
{
where
(
confidential:
true
)
}
...
...
changelogs/unreleased/id-fix-n1-for-issues-api.yml
0 → 100644
View file @
70a0a41c
---
title
:
Fix N+1 for project/:id/issues API endpoint
merge_request
:
37508
author
:
type
:
performance
spec/requests/api/issues/get_project_issues_spec.rb
View file @
70a0a41c
...
...
@@ -180,12 +180,15 @@ RSpec.describe API::Issues do
it
'avoids N+1 queries'
do
get
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
)
create_list
(
:issue
,
3
,
project:
project
)
create_list
(
:issue
,
3
,
project:
project
,
closed_by:
user
)
control_count
=
ActiveRecord
::
QueryRecorder
.
new
(
skip_cached:
false
)
do
get
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
)
end
.
count
milestone
=
create
(
:milestone
,
project:
project
)
create
(
:issue
,
project:
project
,
milestone:
milestone
,
closed_by:
create
(
:user
))
expect
do
get
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
)
end
.
not_to
exceed_all_query_limit
(
control_count
)
...
...
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