Graphql N+1 Triage: requestingReviewAuthorOrAssignee

Summary

requestingReviewAuthorOrAssignee ranked among the top N+1 candidates on gitlab.com, based on 24 hours of production log data. It's estimated to cost 1319.8 avoidable queries per minute. See https://gitlab.com/groups/gitlab-org/-/epics/23614 for how this list was built and the method to follow.

Numbers

Metric Value
Requests in 24h 427,035
N+1 risk 0.96
p95 queries on main replica 155
p95 DB duration (s) 0.878
Estimated savings per minute 1319.8

Where the query comes from

The operation is defined in app/assets/javascripts/merge_request_dashboard/queries/author_or_assignee.query.graphql.

What to do

  1. Find the query source: the .graphql file in the repo, or json.graphql.used_fields in Kibana for external clients.
  2. Write a throwaway request spec, run it against a small and a larger page, and record queries with ActiveRecord::QueryRecorder.new(skip_cached: false).
  3. Fix per-row growth with lookahead preloads, BatchLoader::GraphQL, or a policy preloader in before_connection_authorization.
  4. Add a permanent N+1 spec that asserts query counts don't grow with page size.
  5. After deploy, confirm the savings estimate dropped in the Lens table.

Acceptance criteria

  • Per-row queries identified and listed in this issue.
  • Fix merged.
  • Permanent N+1 spec added.
  • Savings in the Lens table dropped after deploy, or this issue is closed with an explanation of why the spread is fixed cost.
Edited by 🤖 GitLab Bot 🤖