summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorAlexis Reigel <alexis.reigel.ext@siemens.com>2018-09-13 13:45:11 +0200
committerAlexis Reigel <alexis.reigel.ext@siemens.com>2018-09-13 13:45:11 +0200
commitf7ef78a7b5529a345d06b31df067f73c0b6c5833 (patch)
treebca3527ea6667f03539853e64d187590a5ee2bbe /app/models
parentb4e2cc4421c8a836ae26867ac3eec35be079590a (diff)
downloadgitlab-ce-f7ef78a7b5529a345d06b31df067f73c0b6c5833.tar.gz
add a comment to the usage of a anti-pattern query
Diffstat (limited to 'app/models')
-rw-r--r--app/models/ci/runner.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/models/ci/runner.rb b/app/models/ci/runner.rb
index a041ea1a1c8..45fd15a6211 100644
--- a/app/models/ci/runner.rb
+++ b/app/models/ci/runner.rb
@@ -31,6 +31,12 @@ module Ci
scope :active, -> { where(active: true) }
scope :paused, -> { where(active: false) }
scope :online, -> { where('contacted_at > ?', contact_time_deadline) }
+ # The following query using negation is cheaper than using `contacted_at <= ?`
+ # because there are less runners online than have been created. The
+ # resulting query is quickly finding online ones and then uses the regular
+ # indexed search and rejects the ones that are in the previous set. If we
+ # did `contacted_at <= ?` the query would effectively have to do a seq
+ # scan.
scope :offline, -> { where.not(id: online) }
scope :ordered, -> { order(id: :desc) }