Skip to content
Snippets Groups Projects
Commit fba2ec45 authored by Lin Jen-Shin's avatar Lin Jen-Shin
Browse files

Just use order(id: :desc) for latest stuffs:

We don't need that subquery for group by ref and alike here.
parent 1a41cb90
No related branches found
No related tags found
1 merge request!5142Add a download buttons for Build Artifacts
Loading
Loading
@@ -16,7 +16,7 @@ module Ci
scope :with_expired_artifacts, ->() { with_artifacts.where('artifacts_expire_at < ?', Time.now) }
scope :last_month, ->() { where('created_at > ?', Date.today - 1.month) }
scope :latest_success_with_artifacts, ->() do
with_artifacts.success.latest
with_artifacts.success.order(id: :desc)
end
 
mount_uploader :artifacts_file, ArtifactUploader
Loading
Loading
Loading
Loading
@@ -20,14 +20,6 @@ module Ci
after_touch :update_state
after_save :keep_around_commits
 
scope :latest, -> do
max_id = unscope(:select).
select("max(#{table_name}.id)").
group(:ref)
where(id: max_id)
end
def self.truncate_sha(sha)
sha[0...8]
end
Loading
Loading
@@ -226,7 +218,7 @@ module Ci
 
def keep_around_commits
return unless project
project.repository.keep_around(self.sha)
project.repository.keep_around(self.before_sha)
end
Loading
Loading
Loading
Loading
@@ -431,7 +431,7 @@ class Project < ActiveRecord::Base
 
# ref can't be HEAD or SHA, can only be branch/tag name
def latest_success_pipeline_for(ref = 'master')
pipelines.where(ref: ref).success.latest
pipelines.where(ref: ref).success.order(id: :desc)
  • Maintainer

    @godfat

    Should we return a pipeline object here, not a AR object?

    pipelines.where(ref: ref).success.order(id: :desc).first
  • @ayufan If we return an object, then we can't use it in latest_success_builds_for which needs a query instead.

  • Please register or sign in to reply
end
 
# ref can't be HEAD or SHA, can only be branch/tag name
Loading
Loading
  • Maintainer

    I prefer this method to be named:

    latest_successful_pipeline_for
  • Maintainer

    I think that we don't such detailed scope. I would prefer to use scopes of general use.

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment