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

Merge branch 'reduce-queries-for-artifacts-button' into 'master'

Use arrays in Ci::Pipeline#latest_builds_with_artifacts

See merge request gitlab-org/gitlab-ce!15525
parents 6da130c2 54f1e406
...@@ -507,7 +507,10 @@ module Ci ...@@ -507,7 +507,10 @@ module Ci
end end
def latest_builds_with_artifacts def latest_builds_with_artifacts
@latest_builds_with_artifacts ||= builds.latest.with_artifacts # We purposely cast the builds to an Array here. Because we always use the
# rows if there are more than 0 this prevents us from having to run two
# queries: one to get the count and one to get the rows.
@latest_builds_with_artifacts ||= builds.latest.with_artifacts.to_a
end end
private private
......
---
title: Use arrays in Pipeline#latest_builds_with_artifacts
merge_request:
author:
type: performance
...@@ -1502,6 +1502,10 @@ describe Ci::Pipeline, :mailer do ...@@ -1502,6 +1502,10 @@ describe Ci::Pipeline, :mailer do
create(:ci_build, :success, :artifacts, pipeline: pipeline) create(:ci_build, :success, :artifacts, pipeline: pipeline)
end end
it 'returns an Array' do
expect(pipeline.latest_builds_with_artifacts).to be_an_instance_of(Array)
end
it 'returns the latest builds' do it 'returns the latest builds' do
expect(pipeline.latest_builds_with_artifacts).to eq([build]) expect(pipeline.latest_builds_with_artifacts).to eq([build])
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