Optimize catalog component lookups in CI pipeline component usage tracking

Summary

The current implementation in lib/gitlab/ci/pipeline/chain/component_usage.rb calls find_catalog_component for every component in the pipeline, which could cause performance issues when processing pipelines with many non-catalog components.

Current problematic code

included_components.each do |component_hash|
  track_all_components_event(component_hash)
  
  catalog_component = find_catalog_component(component_hash)
  track_catalog_component_event(catalog_component) if catalog_component
end

Suggested optimizations

  1. Filter catalog components upfront before the loop
  2. Batch catalog component lookups to reduce database queries
  3. Cache catalog component lookups within the same pipeline processing

Related to #579780 (closed)

Edited by 🤖 GitLab Bot 🤖