Loading
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
countwithout alimitcounts at most 10,000 releases and returns 10,001 above that, as RESTGET /groups/:id/releasesdoes. An explicitcount(limit:)still applies. The sharedlimitargument description sayscountwithout alimitreturns the exact count; with the flag on that no longer holds forGroup.releases, and the field description says so.- A
last:page withoutbefore: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. hasNextPageon afirst:page comes from reading one row past the page instead of a separate count.BoundedOffsetPageReaderreads these pages, and the connection adapts its result to graphql-ruby.- Nodes, cursors and page info are otherwise unchanged.
Project.releasesand 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:andlast:pages. - With the flag off,
Group.releasespaginates 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
- https://gitlab.com/gitlab-org/gitlab/-/work_items/638259+
- https://gitlab.com/gitlab-org/gitlab/-/work_items/639387+
Database queries
See MR comments.
How to set up and validate locally
- 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) - In
app/graphql/resolvers/group_releases_resolver.rb, setCOUNT_LIMIT = 1, and wait for the reload. - In GraphiQL (
http://gdk.test:3000/-/graphql-explorer), run:{ group(fullPath: "<your-group>") { releases(last: 2) { count pageInfo { hasPreviousPage hasNextPage } nodes { tagName } } } }countreturns 2 and the nodes are the oldest two releases.count(limit: 100)returns the exact count.log/development.logshows noSELECT COUNT(*)without aLIMITfor this request. - Run
Feature.disable(:group_releases_graphql_bounded_counts)and repeat:countis 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