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
.
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
- 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)
-
In this line, instead of
$first
we can hardcode it to be1
. 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. -
In the browser, navigate to
http://gdk.test:3000/groups/<group_full_path>/-/packages
.group_full_path
is thefull_path
of the group created in the console in step1
. -
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 byproject_path
. -
Click on next page, the 2nd package should be displayed correctly.
-
Move to master and repeat the steps starting step
3
, the 2nd page will display nothing.
Related to #448716 (closed)