Skip to content

Fix project_path sorting scopes in Packages::Package model

Context

Package Registry pagination returns empty results after the 1st page on group pages when ordered by project_path.

Example URL: https://gitlab.com/groups/gitlab-org/-/packages?type=&version=&orderBy=project_path&sort=desc&search[]=&after=eyJwcm9qZWN0c19wYXRoIjpudWxsLCJpZCI6IjU5MjE4MDYifQ

What does this MR do and why?

Sorting with project path in package registry UI uses .order_project_path & .order_project_path_desc scopes. The scopes don't generate the correct SQL queries when trying to go to the next page in the UI.

To fix this, we modify the scopes to utilize Sortable.build_keyset_order_on_joined_column method. This method is generating the correct SQL queries that play nicely with the cursor pagination.

MR acceptance checklist

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

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After

How to set up and validate locally

  1. In rails console, create two packages in two different projects in the same group:
# stub file upload
def fixture_file_upload(*args, **kwargs)
  Rack::Test::UploadedFile.new(*args, **kwargs)
end

group = FactoryBot.create(:group)

project1 = FactoryBot.create(:project, group: group)
project2 = FactoryBot.create(:project, group: group)

FactoryBot.create(:package, project: project1)
FactoryBot.create(:package, project: project2)
  1. In this line, instead of $first we can hardcode it to be 1. This way the group's packages UI page will display only one package so that we can test the pagination with our two created packages.

  2. In the browser, navigate to http://gdk.test:3000/groups/<group_full_path>/-/packages. group_full_path is the full_path of the group created in the console in step 1.

  3. On the UI page, you should see one of the two packages. Change the sorting field to Project in the dropdown next to the search bar. This should sort the packages by project_path.

  4. Click on next page, the 2nd package should be displayed correctly.

  5. Move to master and repeat the steps starting step 3, the 2nd page will display nothing.

Related to #448716 (closed)

Edited by Moaz Khalifa

Merge request reports