Optimize the performance of `first_deployment_for`
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
- Get a merge request
- Get a
head_diff_sha
from the merge request -
Find the ref (e.g.
refs/environments/production/deployments/14279
) from the sha - Parse the deployment iid from the ref (e.g.
14279
) - 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
- Get a merge request
- Get a
head_diff_sha
from the merge request - 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?
-
Changelog entry added, if necessary -
Documentation created/updated -
Tests added for this feature/bug -
Conforms to the code review guidelines -
Conforms to the merge request performance guidelines -
Conforms to the style guides -
Conforms to the database guides -
Link to e2e tests MR added if this MR has Requires e2e tests label. See the Test Planning Process.