diff options
| author | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-11-30 23:17:41 +0100 |
|---|---|---|
| committer | Kamil Trzcinski <ayufan@ayufan.eu> | 2017-12-05 16:34:41 +0100 |
| commit | 1efb219561a3be804c30de8e0a74cbfc85b1a4cd (patch) | |
| tree | 4835c94fb1db10acbdbd846805ed3913829ffde0 /app/models/ci | |
| parent | 844d95fb74d0732d4354c4d0ebfdaa5d12e5588e (diff) | |
| download | gitlab-ce-1efb219561a3be804c30de8e0a74cbfc85b1a4cd.tar.gz | |
Perform SQL matching of Build&Runner tags to greatly speed-up job picking
Diffstat (limited to 'app/models/ci')
| -rw-r--r-- | app/models/ci/build.rb | 19 | ||||
| -rw-r--r-- | app/models/ci/runner.rb | 6 |
2 files changed, 22 insertions, 3 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 8738e094510..d2402b55184 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -47,6 +47,25 @@ module Ci scope :manual_actions, ->() { where(when: :manual, status: COMPLETED_STATUSES + [:manual]) } scope :ref_protected, -> { where(protected: true) } + scope :matches_tag_ids, -> (tag_ids) do + matcher = ::ActsAsTaggableOn::Tagging + .where(taggable_type: CommitStatus) + .where(context: 'tags') + .where('taggable_id = ci_builds.id') + .where.not(tag_id: tag_ids).select('1') + + where("NOT EXISTS (?)", matcher) + end + + scope :with_any_tags, -> do + matcher = ::ActsAsTaggableOn::Tagging + .where(taggable_type: CommitStatus) + .where(context: 'tags') + .where('taggable_id = ci_builds.id').select('1') + + where("EXISTS (?)", matcher) + end + mount_uploader :legacy_artifacts_file, LegacyArtifactUploader, mount_on: :artifacts_file mount_uploader :legacy_artifacts_metadata, LegacyArtifactUploader, mount_on: :artifacts_metadata diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb index d39610a8995..dcbb397fb78 100644 --- a/app/models/ci/runner.rb +++ b/app/models/ci/runner.rb @@ -112,7 +112,7 @@ module Ci def can_pick?(build) return false if self.ref_protected? && !build.protected? - assignable_for?(build.project) && accepting_tags?(build) + assignable_for?(build.project_id) && accepting_tags?(build) end def only_for?(project) @@ -171,8 +171,8 @@ module Ci end end - def assignable_for?(project) - is_shared? || projects.exists?(id: project.id) + def assignable_for?(project_id) + is_shared? || projects.exists?(id: project_id) end def accepting_tags?(build) |
