Skip to content

Return empty pipelines in the package API payload

🌱 Context

Some packages can have hundreds or even thousands of associated pipelines. This is a performance problem for the package API endpoint.

#341950 (closed) proposes adding a separate REST API to handle paginated pipelines for a given package, but it is worth noting pagination is already available via GraphQL.

As discussed here, we cannot remove pipelines from the response. What we can do instead is to return a fixed empty array.

What does this MR do and why?

Improve the performance of the GET package API endpoints by returning empty pipelines in the payload.

Screenshots or screen recordings

Example curl request:

curl --header "PRIVATE-TOKEN: glpat-redacted" "http://gdk.test:3001/api/v4/projects/17/packages/107"

Response:

{"id":107,"name":"@mygroup/foo","version":"8.0.3","package_type":"npm","status":"default","_links":{"web_path":"/mygroup/project-a/-/packages/107","delete_api_path":"http://gdk.test:3001/api/v4/projects/17/packages/107"},"created_at":"2023-03-29T10:44:08.333Z","last_downloaded_at":null,"tags":[],"pipeline":{"id":1,"iid":1,"project_id":9,"sha":"2b6127f6bb6f475c4e81afcc2251e3f941e554f9","ref":"mytag","status":"failed","source":"push","created_at":"2023-02-01T12:19:21.895Z","updated_at":"2023-02-01T14:00:05.922Z","web_url":"http://gdk.test:3001/feature-testing/composer-repository/-/pipelines/1","user":{"id":1,"username":"root","name":"Administrator","state":"active","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon","web_url":"http://gdk.test:3001/root"}},"pipelines":[],"versions":[]}                                                                       

How to set up and validate locally

  1. Create a package and run some pipeline jobs for it
  2. Prepare an access token with API access to the package's project
  3. Note down the project ID and the package ID
  4. From the Rails console, enable the feature flag for the project:
project = Project.find(<project_id>)
Feature.enable(:remove_pipeline_from_package_payload, project)
  1. Hit the GET package endpoint:
curl --header "PRIVATE-TOKEN: $YOUR_ACCESS_TOKEN" "http://gdk.test:3001/api/v4/projects/<project_id>/packages/<package_id>"

On the MR branch, the pipelines attribute should be an empty array. On the master branch, the pipelines attribute should be an array containing pipeline info.

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

Edited by Radamanthus Batnag

Merge request reports