Skip to content

Improve performance of jobs controller show

What does this MR do?

Improve performance of JobsController#show.json.

Optimizations:

TL;DR; No N+1 Gitaly calls when there are deployments in a pipeline, no unnecessary Gitaly call whatsoever. A request to Projects::JobsController#show.json should result in 0 additional Gitaly calls.

  1. Calls to Ci::Pipeline#latest? usually require a Gitaly request, but we do not need this information on a build details page, thus this merge request moves serialization of this flag to PipelineDetailsEntity.
  2. Before this change a visit to a build details page resulted in making a request to serialize entire pipeline again (using PipelineDetailsEntity) what was really expensive. We did that only to get a list of stages, and out frontend code actually only needed names of the stages. We now serialize this information once and send it back in a payload from JobsController#show.json. This avoids unnecessary serialization of entire pipeline and saves us another Gitaly request.
  3. Before this change, whenever there was a deployment somewhere in the pipeline, N+1 Gitaly calls were involved in checking an access to a possible protected ref. This was a legitimate Gitaly call, because a latest deployment deployable can be present in a completely different pipeline, on a completely different ref, so caching is difficult. It appears however that we do not display this information anywhere on a build details page, thus we don't really need to serialize that, and this merge request adds deployment_details: false flag.

Metrics

Timings generated using gitlab-structlog from customer's logs:

Before

output

After

TBD

Closes gitlab-org/gitlab-ce#60708

Conformity

Edited by Grzegorz Bizon

Merge request reports