summaryrefslogtreecommitdiff
path: root/app/finders/ci
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/ci')
-rw-r--r--app/finders/ci/pipelines_finder.rb17
-rw-r--r--app/finders/ci/pipelines_for_merge_request_finder.rb66
2 files changed, 26 insertions, 57 deletions
diff --git a/app/finders/ci/pipelines_finder.rb b/app/finders/ci/pipelines_finder.rb
index 39355853d88..712d5f8c6fb 100644
--- a/app/finders/ci/pipelines_finder.rb
+++ b/app/finders/ci/pipelines_finder.rb
@@ -5,6 +5,13 @@ module Ci
attr_reader :project, :pipelines, :params, :current_user
ALLOWED_INDEXED_COLUMNS = %w[id status ref updated_at user_id].freeze
+ ALLOWED_SCOPES = {
+ RUNNING: 'running',
+ PENDING: 'pending',
+ FINISHED: 'finished',
+ BRANCHES: 'branches',
+ TAGS: 'tags'
+ }.freeze
def initialize(project, current_user, params = {})
@project = project
@@ -65,15 +72,15 @@ module Ci
def by_scope(items)
case params[:scope]
- when 'running'
+ when ALLOWED_SCOPES[:RUNNING]
items.running
- when 'pending'
+ when ALLOWED_SCOPES[:PENDING]
items.pending
- when 'finished'
+ when ALLOWED_SCOPES[:FINISHED]
items.finished
- when 'branches'
+ when ALLOWED_SCOPES[:BRANCHES]
from_ids(ids_for_ref(branches))
- when 'tags'
+ when ALLOWED_SCOPES[:TAGS]
from_ids(ids_for_ref(tags))
else
items
diff --git a/app/finders/ci/pipelines_for_merge_request_finder.rb b/app/finders/ci/pipelines_for_merge_request_finder.rb
index 9476c30f525..b623a94541b 100644
--- a/app/finders/ci/pipelines_for_merge_request_finder.rb
+++ b/app/finders/ci/pipelines_for_merge_request_finder.rb
@@ -31,65 +31,27 @@ module Ci
# Fetch all pipelines without permission check.
def all
- ::Gitlab::Database.allow_cross_joins_across_databases(url: 'https://gitlab.com/gitlab-org/gitlab/-/issues/336891') do
- strong_memoize(:all_pipelines) do
- next Ci::Pipeline.none unless source_project
-
- pipelines =
- if merge_request.persisted?
- all_pipelines_for_merge_request
- else
- triggered_for_branch.for_sha(commit_shas)
- end
-
- sort(pipelines)
- end
- end
- end
-
- private
+ strong_memoize(:all_pipelines) do
+ next Ci::Pipeline.none unless source_project
- # rubocop: disable CodeReuse/ActiveRecord
- def pipelines_using_cte
- sha_relation = merge_request.all_commits.select(:sha).distinct
-
- 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)
-
- Ci::Pipeline.with(cte.to_arel) # rubocop: disable CodeReuse/ActiveRecord
- .from_union([pipelines_for_merge_requests, pipelines_for_branch])
- end
- # rubocop: enable CodeReuse/ActiveRecord
+ pipelines =
+ if merge_request.persisted?
+ all_pipelines_for_merge_request
+ else
+ triggered_for_branch.for_sha(commit_shas)
+ end
- def filter_by_sha(pipelines, cte)
- hex = Arel::Nodes::SqlLiteral.new("'hex'")
- string_sha = Arel::Nodes::NamedFunction.new('encode', [cte.table[:sha], hex])
- join_condition = string_sha.eq(Ci::Pipeline.arel_table[:sha])
-
- filter_by(pipelines, cte, join_condition)
+ sort(pipelines)
+ end
end
- def filter_by(pipelines, cte, join_condition)
- shas_table =
- Ci::Pipeline.arel_table
- .join(cte.table, Arel::Nodes::InnerJoin)
- .on(join_condition)
- .join_sources
-
- pipelines.joins(shas_table) # rubocop: disable CodeReuse/ActiveRecord
- end
+ private
def all_pipelines_for_merge_request
- if Feature.enabled?(:decomposed_ci_query_in_pipelines_for_merge_request_finder, target_project, default_enabled: :yaml)
- pipelines_for_merge_request = triggered_by_merge_request
- pipelines_for_branch = triggered_for_branch.for_sha(recent_diff_head_shas(COMMITS_LIMIT))
+ pipelines_for_merge_request = triggered_by_merge_request
+ pipelines_for_branch = triggered_for_branch.for_sha(recent_diff_head_shas(COMMITS_LIMIT))
- Ci::Pipeline.from_union([pipelines_for_merge_request, pipelines_for_branch])
- else
- pipelines_using_cte
- end
+ Ci::Pipeline.from_union([pipelines_for_merge_request, pipelines_for_branch])
end
# NOTE: this method returns only parent merge request pipelines.