Commit e385c50a authored by Patrick Bair's avatar Patrick Bair

Merge branch...

Merge branch '342715-db-timeout-when-loading-environment-in-projects-blobcontroller-show-2' into 'master'

Remove environments_by_deployments_finder_exists_optimization feature flag

See merge request gitlab-org/gitlab!75518
parents db081fe8 ed11580c
......@@ -12,30 +12,18 @@ module Environments
# rubocop: disable CodeReuse/ActiveRecord
def execute
deployments = project.deployments
deployments =
if ref
deployments_query = params[:with_tags] ? 'ref = :ref OR tag IS TRUE' : 'ref = :ref'
deployments.where(deployments_query, ref: ref.to_s)
Deployment.where(deployments_query, ref: ref.to_s)
elsif commit
deployments.where(sha: commit.sha)
Deployment.where(sha: commit.sha)
else
deployments.none
Deployment.none
end
environments =
if Feature.enabled?(:environments_by_deployments_finder_exists_optimization, project, default_enabled: :yaml)
# TODO: replace unscope with deployments = Deployment on top of the method https://gitlab.com/gitlab-org/gitlab/-/issues/343544
project.environments.available
.where('EXISTS (?)', deployments.unscope(where: :project_id).where('environment_id = environments.id'))
else
environment_ids = deployments
.group(:environment_id)
.select(:environment_id)
project.environments.available
.where(id: environment_ids)
end
environments = project.environments.available
.where('EXISTS (?)', deployments.where('environment_id = environments.id'))
if params[:find_latest]
find_one(environments.order_by_last_deployed_at_desc)
......
---
name: environments_by_deployments_finder_exists_optimization
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/72781/
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343544
milestone: '14.5'
type: development
group: group::release
default_enabled: false
......@@ -11,7 +11,7 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do
project.add_maintainer(user)
end
shared_examples 'execute' do
describe '#execute' do
context 'tagged deployment' do
let(:environment_two) { create(:environment, project: project) }
# Environments need to include commits, so rewind two commits to fit
......@@ -124,16 +124,4 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do
end
end
end
describe "#execute" do
include_examples 'execute'
context 'when environments_by_deployments_finder_exists_optimization is disabled' do
before do
stub_feature_flags(environments_by_deployments_finder_exists_optimization: false)
end
include_examples 'execute'
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