Commit 825552bb authored by Igor Drozdov's avatar Igor Drozdov

Merge branch '33741-further-optimise-api-v3-github-endpoints' into 'master'

Further reduce N+1 on Jira pull endpoints

See merge request gitlab-org/gitlab!57658
parents b271f21e 631ee2a5
......@@ -316,7 +316,7 @@ class MergeRequest < ApplicationRecord
}
scope :with_csv_entity_associations, -> { preload(:assignees, :approved_by_users, :author, :milestone, metrics: [:merged_by]) }
scope :with_jira_integration_associations, -> { preload(:metrics, :assignees, :author, :target_project, :source_project) }
scope :with_jira_integration_associations, -> { preload_routables.preload(:metrics, :assignees, :author) }
scope :by_target_branch_wildcard, ->(wildcard_branch_name) do
where("target_branch LIKE ?", ApplicationRecord.sanitize_sql_like(wildcard_branch_name).tr('*', '%'))
......
---
title: Resolve more N+1 issues in Jira pulls API
merge_request: 57658
author:
type: performance
......@@ -197,16 +197,13 @@ module API
# Self-hosted Jira (tested on 7.11.1) requests this endpoint right
# after fetching branches.
# rubocop: disable CodeReuse/ActiveRecord
get ':namespace/:project/events' do
user_project = find_project_with_access(params)
merge_requests = authorized_merge_requests_for_project(user_project)
merge_requests = merge_requests.preload(:author, :assignees, :metrics, source_project: :namespace, target_project: :namespace)
present paginate(merge_requests), with: ::API::Github::Entities::PullRequestEvent
end
# rubocop: enable CodeReuse/ActiveRecord
params do
use :project_full_path
......
......@@ -246,7 +246,10 @@ RSpec.describe API::V3::Github do
control_count = ActiveRecord::QueryRecorder.new { perform_request }.count
create(:merge_request, source_project: project, source_branch: 'fix')
project3 = create(:project, :repository, creator: user)
project3.add_maintainer(user)
assignee3 = create(:user)
create(:merge_request, source_project: project3, target_project: project3, author: user, assignees: [assignee3])
expect { perform_request }.not_to exceed_query_limit(control_count)
end
......
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