Skip to content

Fix AR scopes to support keyset pagination

What does this MR do and why?

This MR fixes broken/wrong GraphQL queries by making the underlying ActiveRecord scopes (new) keyset-pagination compliant. This is the (🤞) last "fix" before removing the old keyset pagination library: #323730 (closed)

How are these queries broken?

The ORDER BY clause of the underlying ActiveRecord scopes did not support keyset pagination. The pagination library should be able to access the values of the order by columns in order to generate the cursor. Example (bad):

Issue.joins(:project).order("projects.name ASC, projects.id ASC")

When getting records for this query, the first page will work perfectly however, the query for the second page will break. To calculate the cursor for the second page, we need to get the issue.project.name and issue.project.id which are not present on the Issue model.

By properly configuring ActiveRecord scopes, the keyset pagination will work.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

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

Related to #323730 (closed)

Edited by Adam Hegyi

Merge request reports

Loading