diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 15:07:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-11-11 15:07:33 +0000 |
commit | 34ce62a494ab1e8f1e76dc4f0bda925593a4c0cb (patch) | |
tree | bdf6d89f15cfac499ff6a750c69d78060b1f3bdd /app/models/ci/build.rb | |
parent | 2761b4465bb13e170f0b8b2941d83f356a47eee6 (diff) | |
download | gitlab-ce-34ce62a494ab1e8f1e76dc4f0bda925593a4c0cb.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/ci/build.rb')
-rw-r--r-- | app/models/ci/build.rb | 53 |
1 files changed, 26 insertions, 27 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 76f92310043..9652323330f 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -72,33 +72,6 @@ module Ci delegate :trigger_short_token, to: :trigger_request, allow_nil: true delegate :ensure_persistent_ref, to: :pipeline - ## - # 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. - # (See more https://gitlab.com/gitlab-org/gitlab-foss/merge_requests/22380) - # - # Since Gitlab 12.9, we started persisting the expanded environment name to - # avoid repeated variables expansion in `action: stop` builds as well. - def persisted_environment - return unless has_environment_keyword? - - strong_memoize(:persisted_environment) do - # This code path has caused N+1s in the past, since environments are only indirectly - # associated to builds and pipelines; see https://gitlab.com/gitlab-org/gitlab/-/issues/326445 - # We therefore batch-load them to prevent dormant N+1s until we found a proper solution. - BatchLoader.for(expanded_environment_name).batch(key: project_id) do |names, loader, args| - Environment.where(name: names, project: args[:key]).find_each do |environment| - loader.call(environment.name, environment) - end - end - end - end - - def persisted_environment=(environment) - strong_memoize(:persisted_environment) { environment } - end - serialize :options # rubocop:disable Cop/ActiveRecordSerialize serialize :yaml_variables, Gitlab::Serializer::Ci::Variables # rubocop:disable Cop/ActiveRecordSerialize @@ -491,6 +464,32 @@ module Ci Gitlab::Ci::Build::Prerequisite::Factory.new(self).unmet end + def persisted_environment + return unless has_environment_keyword? + + strong_memoize(:persisted_environment) do + # This code path has caused N+1s in the past, since environments are only indirectly + # associated to builds and pipelines; see https://gitlab.com/gitlab-org/gitlab/-/issues/326445 + # We therefore batch-load them to prevent dormant N+1s until we found a proper solution. + BatchLoader.for(expanded_environment_name).batch(key: project_id) do |names, loader, args| + Environment.where(name: names, project: args[:key]).find_each do |environment| + loader.call(environment.name, environment) + end + end + end + end + + def persisted_environment=(environment) + strong_memoize(:persisted_environment) { environment } + end + + # If build.persisted_environment is a BatchLoader, we need to remove + # the method proxy in order to clone into new item here + # https://github.com/exAspArk/batch-loader/issues/31 + def actual_persisted_environment + persisted_environment.respond_to?(:__sync) ? persisted_environment.__sync : persisted_environment + end + def expanded_environment_name return unless has_environment_keyword? |