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 ...@@ -12,30 +12,18 @@ module Environments
# rubocop: disable CodeReuse/ActiveRecord # rubocop: disable CodeReuse/ActiveRecord
def execute def execute
deployments = project.deployments
deployments = deployments =
if ref if ref
deployments_query = params[:with_tags] ? 'ref = :ref OR tag IS TRUE' : 'ref = :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 elsif commit
deployments.where(sha: commit.sha) Deployment.where(sha: commit.sha)
else else
deployments.none Deployment.none
end end
environments = environments = project.environments.available
if Feature.enabled?(:environments_by_deployments_finder_exists_optimization, project, default_enabled: :yaml) .where('EXISTS (?)', deployments.where('environment_id = environments.id'))
# 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
if params[:find_latest] if params[:find_latest]
find_one(environments.order_by_last_deployed_at_desc) 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 ...@@ -11,7 +11,7 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do
project.add_maintainer(user) project.add_maintainer(user)
end end
shared_examples 'execute' do describe '#execute' do
context 'tagged deployment' do context 'tagged deployment' do
let(:environment_two) { create(:environment, project: project) } let(:environment_two) { create(:environment, project: project) }
# Environments need to include commits, so rewind two commits to fit # Environments need to include commits, so rewind two commits to fit
...@@ -124,16 +124,4 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do ...@@ -124,16 +124,4 @@ RSpec.describe Environments::EnvironmentsByDeploymentsFinder do
end end
end 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 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