diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2016-07-20 21:46:46 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2016-07-20 21:46:46 +0800 |
commit | 9f70abf185c5d55afc392f2ed39246594c62886d (patch) | |
tree | 137cae63d7408e14f451a79ea2c80c062152976e /app/models | |
parent | a9f3f3c8c9a1656efae35b9837ab4076cc236bf1 (diff) | |
download | gitlab-ce-9f70abf185c5d55afc392f2ed39246594c62886d.tar.gz |
Avoid mixing builds from different pipelines:
So we no longer join anything, just find the latest pipeline
and load builds from there to avoid mixing builds.
Thanks Kamil for the help and tests.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/ci/build.rb | 3 | ||||
-rw-r--r-- | app/models/ci/pipeline.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 9 |
3 files changed, 8 insertions, 6 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 20492c54729..49a123d488b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -15,9 +15,6 @@ module Ci scope :with_artifacts, ->() { where.not(artifacts_file: nil) } scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) } scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) } - scope :latest_successful_with_artifacts, ->() do - with_artifacts.success.order(id: :desc) - end scope :manual_actions, ->() { where(when: :manual) } mount_uploader :artifacts_file, ArtifactUploader diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index 3646baea88e..63246de4692 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -22,7 +22,7 @@ module Ci # ref can't be HEAD or SHA, can only be branch/tag name scope :latest_successful_for, ->(ref = default_branch) do - where(ref: ref).success.order(id: :desc) + where(ref: ref).success.order(id: :desc).limit(1) end def self.truncate_sha(sha) diff --git a/app/models/project.rb b/app/models/project.rb index 5cfc1d407e4..4fd635abbb3 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -431,8 +431,13 @@ class Project < ActiveRecord::Base # ref can't be HEAD, can only be branch/tag name or SHA def latest_successful_builds_for(ref = default_branch) - builds.joins(:pipeline).merge(pipelines.latest_successful_for(ref)). - latest_successful_with_artifacts + latest_successful_pipeline = pipelines.latest_successful_for(ref).first + + if latest_successful_pipeline + latest_successful_pipeline.builds.with_artifacts.latest + else + builds.none + end end def merge_base_commit(first_commit_id, second_commit_id) |