Skip to content

Optimize the performance of `first_deployment_for`

Shinya Maeda requested to merge fix-first-deployment-for into master

What does this MR do?

I think, one of the culprits is the way how we search deployments records that related to a merge request. https://gitlab.com/gitlab-org/gitlab-ce/blob/master/app/models/environment.rb#L105-112 is the current logic though, it works in the ci_environments_status context as the following

  1. Get a merge request
  2. Get a head_diff_sha from the merge request
  3. Find the ref (e.g. refs/environments/production/deployments/14279) from the sha
  4. Parse the deployment iid from the ref (e.g. 14279)
  5. Find deployment record from the iid But, basically, deployments refs are for retaining deployment commits permanently, those are not for searching a corresponding deployment record in the environment.

I'd assume that we can simplify this process as

  1. Get a merge request
  2. Get a head_diff_sha from the merge request
  3. Find deployment record from the sha

What are the relevant issue numbers?

Close https://gitlab.com/gitlab-org/gitlab-ce/issues/51120

Does this MR meet the acceptance criteria?

Merge request reports