Commit 227a664e authored by Kamil Trzcinski's avatar Kamil Trzcinski

Next round

parent 93f9e71b
...@@ -13,18 +13,15 @@ class PipelineSerializer < BaseSerializer ...@@ -13,18 +13,15 @@ class PipelineSerializer < BaseSerializer
def represent(resource, opts = {}) def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation) if resource.is_a?(ActiveRecord::Relation)
project_includes = [ { namespace: :route }, :route ] resource = resource.includes([
resource = resource.includes(
:retryable_builds, :retryable_builds,
:cancelable_statuses, :cancelable_statuses,
:trigger_requests :trigger_requests,
) :project,
resource = resource.includes( { pending_builds: :project },
project: project_includes, { manual_actions: :project },
pending_builds: [:project], { artifacts: :project }
manual_actions: { project: project_includes }, ])
artifacts: { project: project_includes }
)
end end
if paginated? if paginated?
......
...@@ -96,6 +96,7 @@ describe PipelineSerializer do ...@@ -96,6 +96,7 @@ describe PipelineSerializer do
context 'number of queries' do context 'number of queries' do
let(:resource) { Ci::Pipeline.all } let(:resource) { Ci::Pipeline.all }
let(:project) { create(:empty_project) }
before do before do
Ci::Pipeline::AVAILABLE_STATUSES.each do |status| Ci::Pipeline::AVAILABLE_STATUSES.each do |status|
...@@ -112,12 +113,12 @@ describe PipelineSerializer do ...@@ -112,12 +113,12 @@ describe PipelineSerializer do
it "verifies number of queries" do it "verifies number of queries" do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expect(recorded.count).to be_within(10).of(93) expect(recorded.count).to be_within(1).of(50)
expect(recorded.cached_count).to be_within(5).of(5) expect(recorded.cached_count).to eq(0)
end end
def create_pipeline(status) def create_pipeline(status)
create(:ci_empty_pipeline, status: status).tap do |pipeline| create(:ci_empty_pipeline, project: project, status: status).tap do |pipeline|
Ci::Build::AVAILABLE_STATUSES.each do |status| Ci::Build::AVAILABLE_STATUSES.each do |status|
create_build(pipeline, status, status) create_build(pipeline, status, status)
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