Commit ad5f50a3 authored by Kamil Trzciński's avatar Kamil Trzciński

Use an array for fetching same_family_pipeline_ids

The `OR` on DB causes a significant harm when
fetching data from DB, without an index.

We can alleviate it by using a pure `pluck(:id).
parent bd83690e
......@@ -819,15 +819,8 @@ module Ci
# If pipeline is a child of another pipeline, include the parent
# and the siblings, otherwise return only itself and children.
def same_family_pipeline_ids
if (parent = parent_pipeline)
Ci::Pipeline.where(id: parent.id)
.or(Ci::Pipeline.where(id: parent.child_pipelines.select(:id)))
.select(:id)
else
Ci::Pipeline.where(id: self.id)
.or(Ci::Pipeline.where(id: self.child_pipelines.select(:id)))
.select(:id)
end
parent = parent_pipeline || self
[parent.id] + parent.child_pipelines.pluck(:id)
end
def bridge_triggered?
......
---
title: Use an array for fetching same_family_pipeline_ids
merge_request: 36883
author:
type: fixed
......@@ -2684,7 +2684,7 @@ RSpec.describe Ci::Pipeline, :mailer do
context 'when pipeline is not child nor parent' do
it 'returns just the pipeline id' do
expect(same_family_pipeline_ids).to contain_exactly(pipeline)
expect(same_family_pipeline_ids).to contain_exactly(pipeline.id)
end
end
......@@ -2707,7 +2707,7 @@ RSpec.describe Ci::Pipeline, :mailer do
end
it 'returns parent sibling and self ids' do
expect(same_family_pipeline_ids).to contain_exactly(parent, pipeline, sibling)
expect(same_family_pipeline_ids).to contain_exactly(parent.id, pipeline.id, sibling.id)
end
end
......@@ -2723,7 +2723,7 @@ RSpec.describe Ci::Pipeline, :mailer do
end
it 'returns self and child ids' do
expect(same_family_pipeline_ids).to contain_exactly(pipeline, child)
expect(same_family_pipeline_ids).to contain_exactly(pipeline.id, child.id)
end
end
end
......
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