Commit f7648476 authored by Igor Drozdov's avatar Igor Drozdov

Always use expanded env name to load persisted env

Remove FF and accessing env through deployment
parent 2bcfaf6d
...@@ -73,8 +73,7 @@ module Ci ...@@ -73,8 +73,7 @@ module Ci
return unless has_environment? return unless has_environment?
strong_memoize(:persisted_environment) do strong_memoize(:persisted_environment) do
deployment&.environment || Environment.find_by(name: expanded_environment_name, project: project)
Environment.find_by(name: expanded_environment_name, project: project)
end end
end end
...@@ -457,8 +456,7 @@ module Ci ...@@ -457,8 +456,7 @@ module Ci
strong_memoize(:expanded_environment_name) do strong_memoize(:expanded_environment_name) do
# We're using a persisted expanded environment name in order to avoid # We're using a persisted expanded environment name in order to avoid
# variable expansion per request. # variable expansion per request.
if Feature.enabled?(:ci_persisted_expanded_environment_name, project, default_enabled: true) && if metadata&.expanded_environment_name.present?
metadata&.expanded_environment_name.present?
metadata.expanded_environment_name metadata.expanded_environment_name
else else
ExpandVariables.expand(environment, -> { simple_variables }) ExpandVariables.expand(environment, -> { simple_variables })
......
---
title: Always use expanded env name to load persisted environment
merge_request: 37585
author:
type: performance
...@@ -15,21 +15,5 @@ RSpec.describe Ci::BuildPolicy do ...@@ -15,21 +15,5 @@ RSpec.describe Ci::BuildPolicy do
subject { user.can?(:update_build, build) } subject { user.can?(:update_build, build) }
it_behaves_like 'protected environments access' it_behaves_like 'protected environments access'
context 'when a pipeline has manual deployment job' do
let!(:build) { create(:ee_ci_build, :with_deployment, :manual, :deploy_to_production, pipeline: pipeline) }
before do
project.add_developer(user)
end
it 'does not expand environment name' do
allow(build.project).to receive(:protected_environments_feature_available?) { true }
expect(build.project).to receive(:protected_environment_accessible_to?)
expect(build).not_to receive(:expanded_environment_name)
subject
end
end
end end
end end
...@@ -1195,18 +1195,6 @@ RSpec.describe Ci::Build do ...@@ -1195,18 +1195,6 @@ RSpec.describe Ci::Build do
is_expected.to eq('review/host') is_expected.to eq('review/host')
end end
context 'when ci_persisted_expanded_environment_name feature flag is disabled' do
before do
stub_feature_flags(ci_persisted_expanded_environment_name: false)
end
it 'returns an expanded environment name with a list of variables' do
expect(build).to receive(:simple_variables).once.and_call_original
is_expected.to eq('review/host')
end
end
end end
end end
...@@ -2009,23 +1997,13 @@ RSpec.describe Ci::Build do ...@@ -2009,23 +1997,13 @@ RSpec.describe Ci::Build do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
context 'when build has a start environment' do
let(:build) { create(:ci_build, :with_deployment, :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 context 'when build has a stop environment' do
let(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline) } let(:build) { create(:ci_build, :stop_review_app, pipeline: pipeline, environment: "foo-#{project.default_branch}") }
it 'expands environment name' do it 'expands environment name' do
expect(build).to receive(:expanded_environment_name) expect(build).to receive(:expanded_environment_name).and_call_original
subject is_expected.to eq(environment)
end end
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