diff options
Diffstat (limited to 'app/finders/ci')
-rw-r--r-- | app/finders/ci/daily_build_group_report_results_finder.rb | 13 | ||||
-rw-r--r-- | app/finders/ci/pipelines_finder.rb | 12 | ||||
-rw-r--r-- | app/finders/ci/pipelines_for_merge_request_finder.rb | 29 |
3 files changed, 38 insertions, 16 deletions
diff --git a/app/finders/ci/daily_build_group_report_results_finder.rb b/app/finders/ci/daily_build_group_report_results_finder.rb index ec41d9d2c45..ef97ccb4c0f 100644 --- a/app/finders/ci/daily_build_group_report_results_finder.rb +++ b/app/finders/ci/daily_build_group_report_results_finder.rb @@ -4,7 +4,7 @@ module Ci class DailyBuildGroupReportResultsFinder include Gitlab::Allowable - def initialize(current_user:, project:, ref_path:, start_date:, end_date:, limit: nil) + def initialize(current_user:, project:, ref_path: nil, start_date:, end_date:, limit: nil) @current_user = current_user @project = project @ref_path = ref_path @@ -35,11 +35,18 @@ module Ci end def query_params - { + params = { project_id: project, - ref_path: ref_path, date: start_date..end_date } + + if ref_path.present? + params[:ref_path] = ref_path + else + params[:default_branch] = true + end + + params end def none diff --git a/app/finders/ci/pipelines_finder.rb b/app/finders/ci/pipelines_finder.rb index 7347a83d294..a77faebb160 100644 --- a/app/finders/ci/pipelines_finder.rb +++ b/app/finders/ci/pipelines_finder.rb @@ -18,7 +18,9 @@ module Ci return Ci::Pipeline.none end - items = pipelines.no_child + items = pipelines + items = items.no_child unless params[:iids].present? + items = by_iids(items) items = by_scope(items) items = by_status(items) items = by_ref(items) @@ -52,6 +54,14 @@ module Ci project.repository.tag_names end + def by_iids(items) + if params[:iids].present? + items.for_iid(params[:iids]) + else + items + end + end + def by_scope(items) case params[:scope] when 'running' diff --git a/app/finders/ci/pipelines_for_merge_request_finder.rb b/app/finders/ci/pipelines_for_merge_request_finder.rb index 93d139652b9..da8dfc2579a 100644 --- a/app/finders/ci/pipelines_for_merge_request_finder.rb +++ b/app/finders/ci/pipelines_for_merge_request_finder.rb @@ -5,8 +5,6 @@ module Ci class PipelinesForMergeRequestFinder include Gitlab::Utils::StrongMemoize - EVENT = 'merge_request_event' - def initialize(merge_request, current_user) @merge_request = merge_request @current_user = current_user @@ -36,7 +34,11 @@ module Ci pipelines = if merge_request.persisted? - pipelines_using_cte + if Feature.enabled?(:ci_pipelines_for_merge_request_finder_new_cte, target_project) + pipelines_using_cte + else + pipelines_using_legacy_cte + end else triggered_for_branch.for_sha(commit_shas) end @@ -47,7 +49,7 @@ module Ci private - def pipelines_using_cte + def pipelines_using_legacy_cte cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha)) source_sha_join = cte.table[:sha].eq(Ci::Pipeline.arel_table[:source_sha]) @@ -59,6 +61,16 @@ module Ci .from_union([merged_result_pipelines, detached_merge_request_pipelines, pipelines_for_branch]) end + def pipelines_using_cte + cte = Gitlab::SQL::CTE.new(:shas, merge_request.all_commits.select(:sha)) + + 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 + def filter_by_sha(pipelines, cte) hex = Arel::Nodes::SqlLiteral.new("'hex'") string_sha = Arel::Nodes::NamedFunction.new('encode', [cte.table[:sha], hex]) @@ -84,14 +96,7 @@ module Ci end def triggered_for_branch - source_project.ci_pipelines - .where(source: branch_pipeline_sources, ref: source_branch, tag: false) # rubocop: disable CodeReuse/ActiveRecord - end - - def branch_pipeline_sources - strong_memoize(:branch_pipeline_sources) do - Ci::Pipeline.sources.reject { |source| source == EVENT }.values - end + source_project.all_pipelines.ci_branch_sources.for_branch(source_branch) end def sort(pipelines) |