Skip to content

Fix PipelineController#index N+1

Matthias Käppler requested to merge 321788-fix-n-plus-1s into master

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

Availability and Testing

Edited by Matthias Käppler

Merge request reports