Commit d45d1509 authored by Tiger Watson's avatar Tiger Watson

Merge branch 'use_distinct_in_pipeline_shas_cte' into 'master'

Use DISTINCT in MR finder SHAs CTE [RUN ALL RSPEC] [RUN AS-IF-FOSS]

See merge request gitlab-org/gitlab!61454
parents 5e4d2bfe 76d01d28
......@@ -45,8 +45,12 @@ module Ci
private
# rubocop: disable CodeReuse/ActiveRecord
def pipelines_using_cte
cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha))
sha_relation = merge_request.all_commits.select(:sha)
sha_relation = sha_relation.distinct if Feature.enabled?(:use_distinct_in_shas_cte)
cte = Gitlab::SQL::CTE.new(:shas, sha_relation)
pipelines_for_merge_requests = triggered_by_merge_request
pipelines_for_branch = filter_by_sha(triggered_for_branch, cte)
......@@ -54,6 +58,7 @@ module Ci
Ci::Pipeline.with(cte.to_arel) # rubocop: disable CodeReuse/ActiveRecord
.from_union([pipelines_for_merge_requests, pipelines_for_branch])
end
# rubocop: enable CodeReuse/ActiveRecord
def filter_by_sha(pipelines, cte)
hex = Arel::Nodes::SqlLiteral.new("'hex'")
......
---
name: use_distinct_in_shas_cte
introduced_by_url:
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/330586
milestone: '13.12'
type: development
group: group::optimize
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