summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2017-04-08 23:56:13 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2017-04-12 21:17:50 +0200
commit0f1452c2d1a59f8460b01eee7ae4a1ef51f41514 (patch)
treea04ca5756b34a9b1e08195ba255ab6196dbd486e
parent3d1cade13f61115b63bf6dbda5a1f194ba54b24b (diff)
downloadgitlab-ce-fix-performance-regression.tar.gz
Fix performance regression when displaying builds and pipelinesfix-performance-regression
-rw-r--r--app/models/commit_status.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 2c4033146bf..3e736641380 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -20,9 +20,14 @@ class CommitStatus < ActiveRecord::Base
alias_attribute :author, :user
scope :latest, -> do
- max_id = unscope(:select).select("max(#{quoted_table_name}.id)")
-
- where(id: max_id.group(:name, :commit_id))
+ latest_for_pipeline = <<-SQL.strip_heredoc
+ SELECT max(other_builds.id)
+ FROM #{quoted_table_name} other_builds
+ WHERE other_builds.commit_id = ci_builds.commit_id
+ GROUP BY other_builds.name
+ SQL
+
+ where("#{quoted_table_name}.id IN (#{latest_for_pipeline})")
end
scope :failed_but_allowed, -> do