Commit 53582e21 authored by Matthias Käppler's avatar Matthias Käppler Committed by Kamil Trzciński

Fix PipelineController#index N+1

parent d6b39535
...@@ -43,14 +43,14 @@ class PipelineSerializer < BaseSerializer ...@@ -43,14 +43,14 @@ class PipelineSerializer < BaseSerializer
:cancelable_statuses, :cancelable_statuses,
:latest_statuses_ordered_by_stage, :latest_statuses_ordered_by_stage,
:latest_builds_report_results, :latest_builds_report_results,
:manual_actions,
:retryable_builds, :retryable_builds,
:scheduled_actions,
:stages, :stages,
:latest_statuses, :latest_statuses,
:trigger_requests, :trigger_requests,
:user, :user,
{ {
manual_actions: :metadata,
scheduled_actions: :metadata,
downloadable_artifacts: { downloadable_artifacts: {
project: [:route, { namespace: :route }], project: [:route, { namespace: :route }],
job: [] job: []
......
---
title: Fix N+1s related to per-build metadata lookups
merge_request: 55053
author:
type: performance
...@@ -209,6 +209,22 @@ RSpec.describe PipelineSerializer do ...@@ -209,6 +209,22 @@ RSpec.describe PipelineSerializer do
end end
end end
context 'with scheduled and manual builds' do
let(:ref) { 'feature' }
before do
create(:ci_build, :scheduled, pipeline: resource.first)
create(:ci_build, :scheduled, pipeline: resource.second)
create(:ci_build, :manual, pipeline: resource.first)
create(:ci_build, :manual, pipeline: resource.second)
end
it 'sends at most one metadata query for each type of build', :request_store do
# 1 for the existing failed builds and 2 for the added scheduled and manual builds
expect { subject }.not_to exceed_query_limit(1 + 2).for_query /SELECT "ci_builds_metadata".*/
end
end
def create_pipeline(status) def create_pipeline(status)
create(:ci_empty_pipeline, create(:ci_empty_pipeline,
project: project, project: project,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment