Fix PipelineController#index N+1
What does this MR do?
Related to #321788
Fixes an N+1 in the PipelineDetailsEntity
(rendered from PipelineController#index
) where build metadata was queried for every build in the result set.
Done by preloading metadata
for manual_actions
and scheduled_actions
. We were already doing this for failed_builds
, but not for these two. I'm not 100% sure if there are others I am not catching here.
Before:
1) PipelineSerializer#represent number of queries when preloaded with scheduled and manual builds sends at most one metadata query for each type of build
Failure/Error: expect(count_queries_matching(run, "SELECT \"ci_builds_metadata\".*")).to eq(1 + 2)
expected: 3
got: 5
After:
sends at most one metadata query for each type of build
Finished in 1 minute 0.07 seconds (files took 10.82 seconds to load)
1 example, 0 failures
i.e. this will reduce query count from build_types_queried * num_builds_of_this_type
to just build_types_queried * 1
. The gain of this will largely depend on how many builds there are of types scheduled
or manual
.
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry - [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides - [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Edited by Matthias Käppler