summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlejandro Rodríguez <alejorro70@gmail.com>2018-04-24 16:09:57 -0300
committerAlejandro Rodríguez <alejorro70@gmail.com>2018-04-24 16:09:57 -0300
commit19a05acbe99782ac96abc3f8a8e415f23e2ab85e (patch)
tree1f20f75c898de693c4dc9f0d3bcf62d76d736805
parent160f1fd225944b4cedd9d5223cdc55b2f3ed0ea7 (diff)
downloadgitlab-ce-build-scope-optimization.tar.gz
Optimize `with_artifacts_archive` scope on Ci::Buildbuild-scope-optimization
-rw-r--r--app/models/ci/build.rb4
1 files changed, 2 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 4aa65bf4273..e97b37864f1 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -50,8 +50,8 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
scope :with_artifacts_archive, ->() do
- where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
- '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id').archive)
+ joins('LEFT JOIN ci_job_artifacts ON ci_builds.id = ci_job_artifacts.job_id AND ci_job_artifacts.file_type = ', Ci::JobArtifact.file_types[:archive].to_s)
+ .where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR ci_job_artifacts.job_id IS NOT NULL', '')
end
scope :with_artifacts_stored_locally, -> { with_artifacts_archive.where(artifacts_file_store: [nil, LegacyArtifactUploader::Store::LOCAL]) }
scope :with_artifacts_not_expired, ->() { with_artifacts_archive.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }