Investigate and fix incorrect N + 1 query specs in Merge request domain

MR: Pending

Description

Spin off from: !219362 (comment 3035659027)

While attempting to fix an observed performance regression in Stop preloading diff commits (!219362), we identified N + 1 queries in global search merge request lookups. These N + 1 queries apparently always existed, but were skipped over in the specs due to setup differences ( the specs need Elasticsearch enabled on pipelines to pass, but this is not a default due to setup costs); a threshold was added to allow the specs to pass as is.

We also found out that some specs on the merge request API silently allowed N + 1 lookups to pass due to incorrect setup. These specs were rewritten, and a threshold was added to allow existing code to pass.

This issue aims to provide context to thresholds placed in the code, and as a reference point to either fix the N + 1 queries, or to link to specs where a threshold was needed due to the original setup to catch these queries not being correct

Acceptance criteria

Implementation plan

Edited Feb 01, 2026 by Safwan Ahmed
Assignee Loading
Time tracking Loading