summaryrefslogtreecommitdiff
path: root/app/models/ci
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-11-21 17:32:12 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2017-11-21 17:40:29 +0100
commit54f1e406f40a31c6d790bdeabc55556a268990e1 (patch)
tree50ce60e6931cc2da6a96bfa712bf699b1273b030 /app/models/ci
parent9024875e1f81a3aab3c0879d33a4cea912ce833d (diff)
downloadgitlab-ce-54f1e406f40a31c6d790bdeabc55556a268990e1.tar.gz
Use arrays in Pipeline#latest_builds_with_artifactsreduce-queries-for-artifacts-button
This changes Ci::Pipeline#latest_builds_with_artifacts so it returns an Array instead of a relation. Whenever we use this data we do so in two steps: 1. Count the number of rows 2. If this number is greater than 0, iterate over the rows By returning an Array instead we only execute 1 query of which the total time/work is less than running either just a COUNT(*) or both queries (in the worst case). On GitLab.com this change should save us a few milliseconds per request to ProjectsController#show.
Diffstat (limited to 'app/models/ci')
-rw-r--r--app/models/ci/pipeline.rb5
1 files changed, 4 insertions, 1 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 3ded675bec0..ebbefc51a4f 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -507,7 +507,10 @@ module Ci
end
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
private