diff options
author | Shinya Maeda <shinya@gitlab.com> | 2019-02-04 09:41:26 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2019-02-05 14:49:56 +0900 |
commit | bd2ebeda84e4a36d58713c7d9314ad44ff6d89ed (patch) | |
tree | 660fed5cbc170aceba4fb9f843581b0325bce96d /app/models | |
parent | 7f880007d41f0281833915b635244c03a4083b40 (diff) | |
download | gitlab-ce-bd2ebeda84e4a36d58713c7d9314ad44ff6d89ed.tar.gz |
Backport: Optimize slow pipelines.js response
Add changelog
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 84010e40ef4..6b2b7e77180 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -48,13 +48,23 @@ module Ci delegate :trigger_short_token, to: :trigger_request, allow_nil: true ## - # The "environment" field for builds is a String, and is the unexpanded name! + # Since Gitlab 11.5, deployments records started being created right after + # `ci_builds` creation. We can look up a relevant `environment` through + # `deployment` relation today. This is much more efficient than expanding + # environment name with variables. + # (See more https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22380) # + # However, we have to still expand environment name if it's a stop action, + # because `deployment` persists information for start action only. + # + # We will follow up this by persisting expanded name in build metadata or + # persisting stop action in database. def persisted_environment return unless has_environment? strong_memoize(:persisted_environment) do - Environment.find_by(name: expanded_environment_name, project: project) + deployment&.environment || + Environment.find_by(name: expanded_environment_name, project: project) end end |