summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-29 14:46:27 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-03-29 14:49:32 +0200
commit1cc96d7a622cd754674ae8184268acf41a0be7d7 (patch)
treeffc662c4af70e1f6dd0253c6ff932d7730401ad3 /app
parent1a84f96a0602c9e6a9dfd2e2de3cfbe9385470ff (diff)
downloadgitlab-ce-1cc96d7a622cd754674ae8184268acf41a0be7d7.tar.gz
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.
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/build.rb14
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