Skip to content

Update CI catalog resources name sort to use denormalized column

Leaminn Ma requested to merge ci-catalog-use-dernomalized-col-for-name-sort into master

What does this MR do and why?

In !134708 (merged) we denormalized the columns name and description from the projects table and added them to the catalog_resources table (along with trigram indexes on both columns). Now we can use these columns directly instead of relying on JOIN-ing with the projects table.

We can also remove Project.sorted_by_name_desc and Project.sorted_by_name_asc. They were originally introduced in !118802 (diffs) in order to support keyset pagination with the .merge operation. With this MR, we no longer need them to serve that purpose. Both methods are also not used anywhere else so we can remove it.

Resolves Step 3 of #427928 (closed).

Query plan

SELECT "catalog_resources".* FROM "catalog_resources" ORDER BY "catalog_resources"."name" DESC NULLS LAST

Query plan link: Looks good; https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/23439/commands/75341

Query plan for ASC is the same ^.

How to set up and validate locally

  1. Under the same parent group, create 3 projects with README files and any description, named: AA Project, BB Project, and CC Project.
  2. In the console, convert projects to catalog resources in the following order:
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'AA Project'))
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'CC Project'))
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'BB Project'))
  1. Go to http://gdk.test:3000/ and test the following query (update the group name as necessary; use scope: "all" if it has replaced projectPath by now.):
query {
  ciCatalogResources(projectPath: "group-a/aa-project") {
    nodes {
      id
      name
    }
  }
}

Observe that the resources are returned in the following order: Screenshot_2023-10-26_at_11.34.31_AM

  1. Now add a sort argument to the query:
query {
  ciCatalogResources(projectPath: "group-a/aa-project", sort: NAME_ASC) {
    nodes {
      id
      name
    }
  }
}

Observe that the resources are returned in ascending alphabetical order.

  1. Update the sort parameter to NAME_DESC. Observe that the resources are returned in descending alphabetical order.

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 #427928 (closed)

Edited by Leaminn Ma

Merge request reports