Skip to content

GraphQL connection class and Packages finders updates

🦋 Context

Changes extracted from !82496 (merged) where we want to fix several caveats around pipelines object through packages:

  • too many objects loaded
  • n+1 situations.

That's issue #347220 (closed).

To support the fix, we need a few things:

  • A new GraphQL pagination class to handled array of ActiveRecords.
  • Update packages finders to let clients choose if they want to preload pipelines or not.

🔍 What does this MR do and why?

  • Add Gitlab::Graphql::Pagination::ActiveRecordArrayConnection class
  • Update Packages::GroupPackagesFinder and Packages::PackagesFinder so that pipeline association can be stopped from being preloaded.
  • Update the related specs.

These changes has no impact on any user facing feature. As such, changelog entries have not been added. The related changelog will be added in !82496 (merged).

📺 Screenshots or screen recordings

n / a

🔧 How to set up and validate locally

We can't test the pagination class since it's not connected to any GraphQL field yet.

We can test the finders changes:

  1. Create a Group
  2. Create several Projects
  3. For each project, open a rails console and execute:
    def fixture_file_upload(*args, **kwargs)
      Rack::Test::UploadedFile.new(*args, **kwargs)
    end
    
    pkg = FactoryBot.create(:npm_package, project: Project.find(<project_id>))
    
    # creates 5 pipelines
    5.times { Packages::BuildInfo.create!(package_id: pkg.id, pipeline_id: FactoryBot.create(:ci_pipeline).id) }
  4. Try to use the group level packages finder:
    Packages::GroupPackagesFinder.new(User.first, <group>, preload_pipelines: false).execute
  5. Try to use the project level packages finder:
    Packages::PackagesFinder.new(<project>, preload_pipelines: false).execute
  6. In both cases, the pipelines are not loaded.

📐 MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by David Fernandez

Merge request reports