Commit a1eb1f4e authored by Stan Hu's avatar Stan Hu

Merge branch '211373-remove-notes-preload-in-issues-api' into 'master'

Improve performance of Project issues API

See merge request gitlab-org/gitlab!60981
parents 0db5382b f8d30ad2
......@@ -123,7 +123,7 @@ class Issue < ApplicationRecord
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,
preload(:timelogs, :closed_by, :assignees, :author, :labels,
milestone: { project: [:route, { namespace: :route }] },
project: [:route, { namespace: :route }])
}
......
---
title: Improve performance of project issues API
merge_request: 60981
author:
type: performance
---
title: Remove subscribed field from todos, related issues, and epic issues API
merge_request: 60981
author:
type: fixed
......@@ -107,7 +107,6 @@ Example response:
"award_emoji": "http://localhost:3001/api/v4/projects/8/issues/6/award_emoji",
"project": "http://localhost:3001/api/v4/projects/8"
},
"subscribed": true,
"epic_issue_id": 2
}
]
......
......@@ -51,7 +51,6 @@ Parameters:
"description" : null,
"updated_at" : "2016-01-07T12:44:33.959Z",
"milestone" : null,
"subscribed" : true,
"user_notes_count": 0,
"due_date": null,
"web_url": "http://example.com/example/example/issues/14",
......
......@@ -102,7 +102,6 @@ Example Response:
},
"merge_when_pipeline_succeeds": false,
"merge_status": "cannot_be_merged",
"subscribed": true,
"user_notes_count": 7
},
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-foss/-/merge_requests/7",
......@@ -176,7 +175,6 @@ Example Response:
},
"merge_when_pipeline_succeeds": false,
"merge_status": "cannot_be_merged",
"subscribed": true,
"user_notes_count": 7
},
"target_url": "https://gitlab.example.com/gitlab-org/gitlab-foss/-/merge_requests/7",
......
......@@ -71,7 +71,8 @@ module API
present paginate(related_issues(epic)),
with: EE::API::Entities::EpicIssue,
current_user: current_user
current_user: current_user,
include_subscribed: false
end
end
......
......@@ -21,12 +21,12 @@ module API
related_issues = source_issue.related_issues(current_user) do |issues|
issues.with_api_entity_associations.preload_awardable
end
related_issues.each { |issue| issue.lazy_subscription(current_user, user_project) } # preload subscriptions
present related_issues,
with: Entities::RelatedIssue,
current_user: current_user,
project: user_project
project: user_project,
include_subscribed: false
end
desc 'Relate issues' do
......
......@@ -79,7 +79,7 @@ module API
next unless collection
targets = collection.map(&:target)
options[type] = { issuable_metadata: Gitlab::IssuableMetadata.new(current_user, targets).data }
options[type] = { issuable_metadata: Gitlab::IssuableMetadata.new(current_user, targets).data, include_subscribed: false }
end
end
end
......
......@@ -186,7 +186,7 @@ RSpec.describe API::Issues do
it 'avoids N+1 queries' do
get api("/projects/#{project.id}/issues", user)
create_list(:issue, 3, project: project, closed_by: user)
issues = 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)
......@@ -195,6 +195,9 @@ RSpec.describe API::Issues do
milestone = create(:milestone, project: project)
create(:issue, project: project, milestone: milestone, closed_by: create(:user))
create(:note_on_issue, project: project, noteable: issues[0])
create(:note_on_issue, project: project, noteable: issues[1])
expect do
get api("/projects/#{project.id}/issues", user)
end.not_to exceed_all_query_limit(control_count)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment