Memoize environment-specific methods in build class
The purpose of this memoization is to make getting persisted environment name, and related scoped variables, a little more performant task, because it can be invoked multiple times.
This commit is contained in:
parent
1a84f96a06
commit
1cc96d7a62
1 changed files with 9 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue