Commit 1cc96d7a authored by Grzegorz Bizon's avatar Grzegorz Bizon

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.
parent 1a84f96a
...@@ -6,6 +6,7 @@ module Ci ...@@ -6,6 +6,7 @@ module Ci
include ObjectStorage::BackgroundMove include ObjectStorage::BackgroundMove
include Presentable include Presentable
include Importable include Importable
include Gitlab::Utils::StrongMemoize
MissingDependenciesError = Class.new(StandardError) MissingDependenciesError = Class.new(StandardError)
...@@ -31,10 +32,11 @@ module Ci ...@@ -31,10 +32,11 @@ module Ci
# The "environment" field for builds is a String, and is the unexpanded name! # The "environment" field for builds is a String, and is the unexpanded name!
# #
def persisted_environment def persisted_environment
@persisted_environment ||= Environment.find_by( return unless has_environment?
name: expanded_environment_name,
project: project strong_memoize(:persisted_environment) do
) Environment.find_by(name: expanded_environment_name, project: project)
end
end end
serialize :options # rubocop:disable Cop/ActiveRecordSerialize serialize :options # rubocop:disable Cop/ActiveRecordSerialize
...@@ -213,7 +215,9 @@ module Ci ...@@ -213,7 +215,9 @@ module Ci
end end
def expanded_environment_name def expanded_environment_name
if has_environment? return unless has_environment?
strong_memoize(:expanded_environment_name) do
ExpandVariables.expand(environment, simple_variables) ExpandVariables.expand(environment, simple_variables)
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment