Commit 615aae0a authored by Stan Hu's avatar Stan Hu

Fix Gitaly N+1 queries in related merge requests API

In https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/9661, we
removed the `subscribed` field from API endpoints that needed to return
a list of issues or merge requests when to avoid full Markdown
processing.

However, we introduced a performance regression in GitLab 11.10
(https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/26367) when we
converted `MergeRequestBasic` to `MergeRequest` in order to expose the
head pipeline in the
/api/:version/projects/:id/issues/:issue_iid/related_merge_requests
endpoint.

To avoid this overhead, we now omit the `subscribed` field in this API
endpoint.

Closes https://gitlab.com/gitlab-org/gitlab/issues/32948
parent 6e1f17da
---
title: Fix Gitaly N+1 queries in related merge requests API
merge_request: 17850
author:
type: performance
...@@ -771,7 +771,7 @@ module API ...@@ -771,7 +771,7 @@ module API
end end
class MergeRequest < MergeRequestBasic class MergeRequest < MergeRequestBasic
expose :subscribed do |merge_request, options| expose :subscribed, if: -> (_, options) { options.fetch(:include_subscribed, true) } do |merge_request, options|
merge_request.subscribed?(options[:current_user], options[:project]) merge_request.subscribed?(options[:current_user], options[:project])
end end
......
...@@ -343,7 +343,8 @@ module API ...@@ -343,7 +343,8 @@ module API
present paginate(::Kaminari.paginate_array(merge_requests)), present paginate(::Kaminari.paginate_array(merge_requests)),
with: Entities::MergeRequest, with: Entities::MergeRequest,
current_user: current_user, current_user: current_user,
project: user_project project: user_project,
include_subscribed: false
end end
desc 'List merge requests closing issue' do desc 'List merge requests closing issue' do
......
...@@ -736,6 +736,8 @@ describe API::Issues do ...@@ -736,6 +736,8 @@ describe API::Issues do
get_related_merge_requests(project.id, issue.iid) get_related_merge_requests(project.id, issue.iid)
expect_paginated_array_response(related_mr.id) expect_paginated_array_response(related_mr.id)
expect(response).to have_gitlab_http_status(200)
expect(json_response.last).not_to have_key('subscribed')
end end
it 'renders 404 if project is not visible' do it 'renders 404 if project is not visible' do
......
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