Skip to content

Reduce N+1 approval rules related queries on GraphQL request

What does this MR do and why?

When querying merge requests via GraphQL and querying the mergeable or detailedMergeStatus fields, it can result to N+1 SQL queries when checking for the approval state of the MR.

This removes the N+1 queries problem by preloading associations that are being used in MergeRequests::Mergeability::CheckApprovedService.

Data

Tested this locally with 5 MRs with the same approval rules by requesting the mergeable field:

Overriding approval rules is disabled:

  • Before: 80 SQL queries (0.7s total duration)
  • After: 32 SQL queries (0.4s total duration)

Approval rules are overridden:

  • Before: 84 SQL queries (0.5s duration)
  • After: 30 SQL queries (0.4s duration)

Query plans

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #437975 (closed)

Edited by Patrick Bajao

Merge request reports