Use PipelinePreloader for PolicySchedulePipeline

What does this MR do and why?

Adds partition-aware bulk preloading of Ci::Pipeline associations directly into the Ci::Partitionable::AssociationFinder concern, as part of #601100.

ActiveRecord's standard preload(:pipeline) for belongs_to :pipeline associations on non-CI-DB models issues WHERE id IN (...) against p_ci_pipelines with no partition_id filter, causing a full cross-partition scan. This MR introduces a PipelineRelationPreload module inside AssociationFinder that intercepts AR's preload_associations call, resolves pipeline ids through Gitlab::Ci::Pipeline::BulkByIdLookup (which prunes by partition_id), and feeds the results back via ActiveRecord::Associations::Preloader with available_records:. The feature is gated behind the partition_aware_pipeline_preload feature flag (gitlab_com_derisk, default off).

partitionable_belongs_to_loader now also registers the association name and its foreign key in a partitioned_pipeline_loaders class attribute, so PipelineRelationPreload knows which preloads to intercept.

Changes:

  • Ci::Partitionable::AssociationFinder (app/models/concerns/ci/partitionable/association_finder.rb): adds PipelineRelationPreload module with preload_associations override, with_partition_aware_preload scope helper, and partitioned_pipeline_loaders class attribute populated by partitionable_belongs_to_loader.
  • Gitlab::Ci::Pipeline::BulkByIdLookup (lib/gitlab/ci/pipeline/bulk_by_id_lookup.rb): changed return type from Hash<id, Pipeline> to Array<Pipeline> to align with the available_records: API.
  • Security::PolicySchedulePipeline (ee/app/models/security/policy_schedule_pipeline.rb): adds a preload_pipeline scope using with_partition_aware_preload.preload(:pipeline); preload_pipeline_and_project_route now delegates to it.
  • Ci::Preloaders::PipelinePreloader (app/models/ci/preloaders/pipeline_preloader.rb): removed — superseded by the concern-level approach.
  • Feature flag: partition_aware_pipeline_preload (config/feature_flags/gitlab_com_derisk/partition_aware_pipeline_preload.yml), gitlab_com_derisk type, default disabled.

Tests

  • Updated BulkByIdLookup spec for the new Array return type.
  • Removed Ci::Preloaders::PipelinePreloader spec (class deleted).
  • Added PipelineRelationPreload specs in association_finder_spec.rb: verifies no per-record p_ci_pipelines query, sibling associations still preloaded via super, no-op when no partitioned association is requested, partition pruning with a warm cache, and feature-flag fallback to vanilla AR preload.
  • Added Security::PolicySchedulePipeline .preload_pipeline scope spec.
  • Updated PolicySchedulePipelinesResolver spec with a bulk-preload assertion.

Related to #601100

Edited by Marius Bobin

Merge request reports

Loading