summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Baum <ibaum@gitlab.com>2018-02-17 16:50:08 +0000
committerMark Fletcher <mark@gitlab.com>2018-02-19 11:14:45 +0000
commit8dc1fae03d5519cf28bedc73b082e187e0d67c90 (patch)
tree6ed6e55ed0c4b45bef06fe40caf00017aaebf7ef
parent7db2fc0636ad93666b8b3c209a334bcfe093cca5 (diff)
downloadgitlab-ce-8dc1fae03d5519cf28bedc73b082e187e0d67c90.tar.gz
Merge branch 'revert-215dff76' into 'master'
Revert "Merge branch 'expired-ci-artifacts' into 'master'" See merge request gitlab-org/gitlab-ce!17193
-rw-r--r--app/models/ci/build.rb37
-rw-r--r--changelogs/unreleased/expired-ci-artifacts.yml5
2 files changed, 4 insertions, 38 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 7312e704932..20534b8eed0 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -41,41 +41,12 @@ module Ci
scope :unstarted, ->() { where(runner_id: nil) }
scope :ignore_failures, ->() { where(allow_failure: false) }
-
- # This convoluted mess is because we need to handle two cases of
- # artifact files during the migration. And a simple OR clause
- # makes it impossible to optimize.
-
- # Instead we want to use UNION ALL and do two carefully
- # constructed disjoint queries. But Rails cannot handle UNION or
- # UNION ALL queries so we do the query in a subquery and wrap it
- # in an otherwise redundant WHERE IN query (IN is fine for
- # non-null columns).
-
- # This should all be ripped out when the migration is finished and
- # replaced with just the new storage to avoid the extra work.
-
scope :with_artifacts, ->() do
- old = Ci::Build.select(:id).where(%q[artifacts_file <> ''])
- new = Ci::Build.select(:id).where(%q[(artifacts_file IS NULL OR artifacts_file = '') AND EXISTS (?)],
- Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id'))
- where('ci_builds.id IN (? UNION ALL ?)', old, new)
+ where('(artifacts_file IS NOT NULL AND artifacts_file <> ?) OR EXISTS (?)',
+ '', Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id'))
end
-
- scope :with_artifacts_not_expired, ->() do
- old = Ci::Build.select(:id).where(%q[artifacts_file <> '' AND (artifacts_expire_at IS NULL OR artifacts_expire_at > ?)], Time.now)
- new = Ci::Build.select(:id).where(%q[(artifacts_file IS NULL OR artifacts_file = '') AND EXISTS (?)],
- Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id AND (expire_at IS NULL OR expire_at > ?)', Time.now))
- where('ci_builds.id IN (? UNION ALL ?)', old, new)
- end
-
- scope :with_expired_artifacts, ->() do
- old = Ci::Build.select(:id).where(%q[artifacts_file <> '' AND artifacts_expire_at < ?], Time.now)
- new = Ci::Build.select(:id).where(%q[(artifacts_file IS NULL OR artifacts_file = '') AND EXISTS (?)],
- Ci::JobArtifact.select(1).where('ci_builds.id = ci_job_artifacts.job_id AND expire_at < ?', Time.now))
- where('ci_builds.id IN (? UNION ALL ?)', old, new)
- end
-
+ scope :with_artifacts_not_expired, ->() { with_artifacts.where('artifacts_expire_at IS NULL OR artifacts_expire_at > ?', Time.now) }
+ scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) }
scope :ref_protected, -> { where(protected: true) }
diff --git a/changelogs/unreleased/expired-ci-artifacts.yml b/changelogs/unreleased/expired-ci-artifacts.yml
deleted file mode 100644
index 2fcbdb02f84..00000000000
--- a/changelogs/unreleased/expired-ci-artifacts.yml
+++ /dev/null
@@ -1,5 +0,0 @@
----
-title: Change SQL for expired artifacts to use new ci_job_artifacts.expire_at
-merge_request: 16578
-author:
-type: performance