Add CiCatalogResource `latest_version` GQL field; deprecate `versions`
What does this MR do and why?
This MR accomplishes the following:
- Adds
latest
andlatest_for_projects
methods to theRelease
model to act as the SSoT for the definition of "latest release". Resolves #406627 (closed).-
Ci::Catalog::Resource
andBadge::Release::LatestRelease
have been updated to use the newlatest
SSoT method. - The query for
latest_for_projects
utilizesLATERAL JOIN
and an in-memory table to avoid joining in thereleases
table or using an inefficientIN
clause.
-
- Deprecates the GQL CiCatalogResource
versions
field because it causes performance degradation as it queries each project's entire releases list without aLIMIT
. 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 newlatest_for_projects
method (viaReleasesFinder
). It does not cause N+1 queries and is much more performant than the deprecatedversions
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
- In the Rails console, run
Feature.enable(:ci_namespace_catalog_experimental)
. - Create a Catalog Resource with an existing or new Project:
::Ci::Catalog::Resource.create(project: Project.find(<project_id>))
- 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.)
- 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.)
- Go to
http://gdk.test:3000/-/graphql-explorer
and run the following query (adjust theprojectPath
as necessary):
query getCiCatalogResources {
ciCatalogResources(projectPath: "group-a/project-catalog-resource-1") {
nodes {
id
name
latestVersion {
tagName
releasedAt
author {
id
name
webUrl
}
}
}
}
}
- Observe that the output shows the correct Catalog Resource information along with the latest version data.
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #414500 (closed)
Edited by Leaminn Ma