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): addsPipelineRelationPreloadmodule withpreload_associationsoverride,with_partition_aware_preloadscope helper, andpartitioned_pipeline_loadersclass attribute populated bypartitionable_belongs_to_loader.Gitlab::Ci::Pipeline::BulkByIdLookup(lib/gitlab/ci/pipeline/bulk_by_id_lookup.rb): changed return type fromHash<id, Pipeline>toArray<Pipeline>to align with theavailable_records:API.Security::PolicySchedulePipeline(ee/app/models/security/policy_schedule_pipeline.rb): adds apreload_pipelinescope usingwith_partition_aware_preload.preload(:pipeline);preload_pipeline_and_project_routenow 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_derisktype, default disabled.
Tests
- Updated
BulkByIdLookupspec for the newArrayreturn type. - Removed
Ci::Preloaders::PipelinePreloaderspec (class deleted). - Added
PipelineRelationPreloadspecs inassociation_finder_spec.rb: verifies no per-recordp_ci_pipelinesquery, sibling associations still preloaded viasuper, 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_pipelinescope spec. - Updated
PolicySchedulePipelinesResolverspec with a bulk-preload assertion.
Related to #601100