summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorPaco Guzman <pacoguzmanp@gmail.com>2016-08-23 11:27:22 +0200
committerPaco Guzman <pacoguzmanp@gmail.com>2016-08-25 14:42:18 +0200
commit6280fd3777920670ee42111fddf29576cbf85988 (patch)
treedcb44ce2f9fc19fca073d4818d292996749f2461 /app/models
parent7bbb523b23638c52b3c0ba43d8f3dbef8840aad6 (diff)
downloadgitlab-ce-13912-reduce-pipeline-db-queries.tar.gz
Reduce number of database queries on builds tab13912-reduce-pipeline-db-queries
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--app/models/commit_status.rb2
3 files changed, 4 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 096b3b801af..23c8de6f650 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -352,7 +352,7 @@ module Ci
end
def artifacts?
- !artifacts_expired? && artifacts_file.exists?
+ !artifacts_expired? && self[:artifacts_file].present?
end
def artifacts_metadata?
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index 087abe4cbb1..aff908ea16c 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -83,7 +83,7 @@ module Ci
end
def stages_with_latest_statuses
- statuses.latest.order(:stage_idx).group_by(&:stage)
+ statuses.latest.includes(project: :namespace).order(:stage_idx).group_by(&:stage)
end
def project_id
diff --git a/app/models/commit_status.rb b/app/models/commit_status.rb
index 84ceeac7d3e..1b403fa646d 100644
--- a/app/models/commit_status.rb
+++ b/app/models/commit_status.rb
@@ -25,6 +25,8 @@ class CommitStatus < ActiveRecord::Base
scope :retried, -> { where.not(id: latest) }
scope :ordered, -> { order(:name) }
scope :ignored, -> { where(allow_failure: true, status: [:failed, :canceled]) }
+ scope :latest_ci_stages, -> { latest.ordered.includes(project: :namespace) }
+ scope :retried_ci_stages, -> { retried.ordered.includes(project: :namespace) }
state_machine :status do
event :enqueue do