Commit 0b9673eb authored by lauraMon's avatar lauraMon

Removes cross join in merge request environments

parent 0c5eca15
......@@ -1409,7 +1409,19 @@ class MergeRequest < ApplicationRecord
def environments
return Environment.none unless actual_head_pipeline&.merge_request?
actual_head_pipeline.environments
if ::Feature.enabled?(:avoid_cross_joins_environments_merge_request, default_enabled: :yaml)
build_for_actual_head_pipeline = Ci::Build.latest.where(pipeline: actual_head_pipeline)
environments = build_for_actual_head_pipeline.joins(:metadata)
.where.not('ci_builds_metadata.expanded_environment_name' => nil)
.distinct('ci_builds_metadata.expanded_environment_name')
.limit(100)
.pluck(:expanded_environment_name)
Environment.where(project: project, name: environments)
else
actual_head_pipeline.environments
end
end
def fetch_ref!
......
---
name: avoid_cross_joins_environments_merge_request
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/71591
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/343236
milestone: '14.5'
type: development
group: group::sharding
default_enabled: false
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