Backport: Optimize slow pipelines.js response

Add changelog
This commit is contained in:
Shinya Maeda 2019-02-04 09:41:26 +09:00
parent 7f880007d4
commit bd2ebeda84
3 changed files with 37 additions and 2 deletions

View File

@ -48,13 +48,23 @@ module Ci
delegate :trigger_short_token, to: :trigger_request, allow_nil: true
##
# The "environment" field for builds is a String, and is the unexpanded name!
# 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. This is much more efficient than expanding
# environment name with variables.
# (See more https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/22380)
#
# However, we have to still expand environment name if it's a stop action,
# because `deployment` persists information for start action only.
#
# We will follow up this by persisting expanded name in build metadata or
# persisting stop action in database.
def persisted_environment
return unless has_environment?
strong_memoize(:persisted_environment) do
Environment.find_by(name: expanded_environment_name, project: project)
deployment&.environment ||
Environment.find_by(name: expanded_environment_name, project: project)
end
end

View File

@ -0,0 +1,5 @@
---
title: Use deployment relation to get an environment name
merge_request: 24890
author:
type: performance

View File

@ -1844,6 +1844,26 @@ describe Ci::Build do
context 'when there is no environment' do
it { is_expected.to be_nil }
end
context 'when build has a start environment' do
let(:build) { create(:ci_build, :deploy_to_production, pipeline: pipeline) }
it 'does not expand environment name' do
expect(build).not_to receive(:expanded_environment_name)
subject
end
end
context 'when build has a stop environment' do
let(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline) }
it 'expands environment name' do
expect(build).to receive(:expanded_environment_name)
subject
end
end
end
describe '#play' do