diff options
-rw-r--r-- | app/models/ci/build.rb | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index f8755e1a4ff..b42555e46e4 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -6,6 +6,7 @@ module Ci include ObjectStorage::BackgroundMove include Presentable include Importable + include Gitlab::Utils::StrongMemoize MissingDependenciesError = Class.new(StandardError) @@ -31,10 +32,11 @@ module Ci # The "environment" field for builds is a String, and is the unexpanded name! # def persisted_environment - @persisted_environment ||= Environment.find_by( - name: expanded_environment_name, - project: project - ) + return unless has_environment? + + strong_memoize(:persisted_environment) do + Environment.find_by(name: expanded_environment_name, project: project) + end end serialize :options # rubocop:disable Cop/ActiveRecordSerialize @@ -213,7 +215,9 @@ module Ci end def expanded_environment_name - if has_environment? + return unless has_environment? + + strong_memoize(:expanded_environment_name) do ExpandVariables.expand(environment, simple_variables) end end |