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
andPackages::PackagesFinder
so thatpipeline
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:
- Create a Group
- Create several Projects
- 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) }
- Try to use the group level packages finder:
Packages::GroupPackagesFinder.new(User.first, <group>, preload_pipelines: false).execute
- Try to use the project level packages finder:
Packages::PackagesFinder.new(<project>, preload_pipelines: false).execute
- 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.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by David Fernandez