Skip to content

Preload merge_request_diff_commits when diffStats is requested

What does this MR do and why?

Old MRs have no head_commit_sha in the DB for their MergeRequestDiff records. As a result, when diffStats field is requested via GraphQL, the MergeRequestDiffCommit records get queried per MR to get the head_commit_sha.

This results to N+1 DB queries when mergeRequests are requested via GraphQL API.

To fix this, we preload merge_request_diff_commits when diffStats field is requested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #416505 (closed)

Merge request reports