Skip to content

Update query plan in Ci::Catalog::Listing to use denormalized columns

Leaminn Ma requested to merge ci-catalog-listing-update-query-plan 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 the search functionality from ProjectsFinder.

This MR updates the query plan in Ci::Catalog::Listing by replacing the use of ProjectsFinder with a native search scope on the Ci::Catalog::Resource model. This improves the search query peformance. The overall functionality has not changed.

Resolves Step 4 of #427928 (closed)

Query plan

SELECT "catalog_resources".* FROM "catalog_resources" WHERE ("catalog_resources"."name" ILIKE '%cat%' OR "catalog_resources"."description" ILIKE '%cat%')

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

How to set up and validate locally

Verify that the GraphQl ciCatalogResources search functionality still works as expected:

  1. Under the same parent group, create 2 projects with README files named Orange Project and Apple Project. (These names need to be unique. We simply want to set up a situation where only one or both of these projects are returned by the search filter.)
  2. Update the description of Orange Project to Foo; update the description of Apple Project to Orange.
  3. In the console, first mark Orange Project as a catalog resource, then mark Apple Project as a catalog resource.
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'Orange Project'))
Ci::Catalog::Resource.create!(project: Project.find_by(name: 'Apple 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/orange-project", search: "orange") {
    nodes {
      id
      name
    }
  }
}

Observe that both projects from Step 1 are in the response.

Screenshot_2023-10-23_at_12.36.46_PM

  1. If you change the search term to "apple", then only Apple Project will show.

Screenshot_2023-10-23_at_12.37.26_PM

  1. Optional: You can additionally test the search with a sort param:
query {
  ciCatalogResources(projectPath: "group-a/orange-project", search: "orange", sort: NAME_DESC) {
    nodes {
      id
      name
    }
  }
}

Orange Project should appear first in the list.

Screenshot_2023-10-23_at_12.42.26_PM

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