Skip to content

Add CiCatalogResource `latest_version` GQL field; deprecate `versions`

Leaminn Ma requested to merge gdl-ci-catalog-latest-version into master

What does this MR do and why?

This MR accomplishes the following:

  • Adds latest and latest_for_projects methods to the Release model to act as the SSoT for the definition of "latest release". Resolves #406627 (closed).
    • Ci::Catalog::Resource and Badge::Release::LatestRelease have been updated to use the new latest SSoT method.
    • The query for latest_for_projects utilizes LATERAL JOIN and an in-memory table to avoid joining in the releases table or using an inefficient IN clause.
  • Deprecates the GQL CiCatalogResource versions field because it causes performance degradation as it queries each project's entire releases list without a LIMIT. It's also an unnecessary field as we only need to obtain the "latest version" (equivalent to "latest release") for each catalog resource object.
  • Adds the latest_version GQL field which utilizes the new latest_for_projects method (via ReleasesFinder). It does not cause N+1 queries and is much more performant than the deprecated versions field. The performance improvement is sufficient to allow this shortcut field implementation.

Resolves both #414500 (closed) and #406627 (closed).

How to set up and validate locally

  1. In the Rails console, run Feature.enable(:ci_namespace_catalog_experimental).
  2. Create a Catalog Resource with an existing or new Project:
::Ci::Catalog::Resource.create(project: Project.find(<project_id>))
  1. Ensure that the Project has a non-empty description and also has a README file. (This is required for you to successfully create a Release on the Catalog Resource.)
  2. Create at least one Tag and one Release on the Project. (Note that the latest Release is equivalent to the "latest version" of the Catalog Resource.)
  3. Go to http://gdk.test:3000/-/graphql-explorer and run the following query (adjust the projectPath as necessary):
query getCiCatalogResources {
  ciCatalogResources(projectPath: "group-a/project-catalog-resource-1") {
    nodes {
      id
      name
      latestVersion {
        tagName
        releasedAt
        author {
          id
          name
          webUrl
        }
      }
    }
  }
}
  1. Observe that the output shows the correct Catalog Resource information along with the latest version data.
Screenshot Screenshot_2023-06-13_at_9.34.36_PM

Query Plan

SELECT "releases".* FROM "releases" WHERE "releases"."project_id" = 278964 ORDER BY "releases"."released_at" DESC LIMIT 1

Query plan link: https://console.postgres.ai/shared/a72217b8-8e97-47f2-ae01-bea68f5b31e1

SELECT "releases".* FROM (VALUES (278964),(7764),(15683922)) projects (id) INNER JOIN LATERAL (SELECT "releases".* FROM "releases" WHERE "projects"."id" = "releases"."project_id" ORDER BY "releases"."released_at" DESC LIMIT 1) releases ON TRUE

Query plan link: https://console.postgres.ai/shared/874feeda-2de6-488f-ac8b-7a8403e16aa5

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

Edited by Leaminn Ma

Merge request reports