Skip to content

Avoid the next page check query in GraphQL

Adam Hegyi requested to merge eliminate-keyset-next-page-check into master

What does this MR do and why?

This MR removes the extra next page check query from GraphQL. The old implementation runs an additional DB query (OFFSET $PAGE_SIZE + 1 LIMIT 1) to check if there is a next page. In some cases, the check query is as expensive as the actual query that loads the records.

How

Request LIMIT + 1 records but only return LIMIT records. Use the last (not used) record to determine if there is a next page.

Example:

image

With this MR the second query will not happen.

How to set up and validate locally

  1. Enable the invite modal
    Feature.enable(:graphql_keyset_pagination_without_next_page_query)
  2. In a group, create a new label and go to a project (copy the project id).
  3. Generate some issues
      15.times { FactoryBot.create(:labeled_issue, project: Project.find("YOUR_PROJECT_ID"), labels: [Label.find_by_name("YOUR_LABEL_NAME")] ) }
  4. Got to group / issues / boards
  5. Create a new board and add a list with the created label
  6. Inspect the executed SQL queries. You should see only one query for the issues table.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Adam Hegyi

Merge request reports