Bound counts in GraphQL group releases pagination

What does this MR do and why?

Context

GraphQL Group.releases counts every release in the group's hierarchy for count, for a last: page and for pageInfo.hasNextPage, so the cost of a request grows with the number of releases in the group. The figures and the agreed approach are in https://gitlab.com/gitlab-org/gitlab/-/work_items/638259#note_4197970429.

This MR

  • count without a limit counts at most 10,000 releases and returns 10,001 above that, as REST GET /groups/:id/releases does. An explicit count(limit:) still applies. The shared limit argument description says count without a limit returns the exact count; with the flag on that no longer holds for Group.releases, and the field description says so.
  • A last: page without before: reads its rows from the other end of the list, through the group releases finder's new #reversed, and reverses them. It runs the exact count only when the query selects a cursor that needs it.
  • hasNextPage on a first: page comes from reading one row past the page instead of a separate count.
  • BoundedOffsetPageReader reads these pages, and the connection adapts its result to graphql-ruby.
  • Nodes, cursors and page info are otherwise unchanged. Project.releases and every other countable connection are unchanged.
  • The pages still go through the group releases finder's bounded page query from !269114 (merged). A request spec checks this for first: and last: pages.
  • With the flag off, Group.releases paginates as before.
  • The Changelog entry comes with the flag-removal MR.

The rollout waits until group_releases_bounded_queries (!269114 (merged)) is fully on, because the capped count is cheap only on that flag's query.

Feature Flag: group_releases_graphql_bounded_counts

References

Database queries

See MR comments.

How to set up and validate locally

  1. In a Rails console, pick a group whose projects have a few releases, and enable both flags:
    group = Group.find_by_full_path('<your-group>')
    Feature.enable(:group_releases_bounded_queries)
    Feature.enable(:group_releases_graphql_bounded_counts)
  2. In app/graphql/resolvers/group_releases_resolver.rb, set COUNT_LIMIT = 1, and wait for the reload.
  3. In GraphiQL (http://gdk.test:3000/-/graphql-explorer), run:
    { group(fullPath: "<your-group>") { releases(last: 2) { count pageInfo { hasPreviousPage hasNextPage } nodes { tagName } } } }
    count returns 2 and the nodes are the oldest two releases. count(limit: 100) returns the exact count. log/development.log shows no SELECT COUNT(*) without a LIMIT for this request.
  4. Run Feature.disable(:group_releases_graphql_bounded_counts) and repeat: count is exact and the nodes and page info are the same.

MR acceptance checklist

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

Edited by Leaminn Ma

Merge request reports

Loading
Loading