Commit dc2616c1 authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '335733-faster-ci-runners-query' into 'master'

Resolve "Slow ci runners query at /api/:version/runners"

See merge request gitlab-org/gitlab!66352
parents 903d7905 9787f5b3
...@@ -61,13 +61,7 @@ module Ci ...@@ -61,13 +61,7 @@ module Ci
scope :paused, -> { where(active: false) } scope :paused, -> { where(active: false) }
scope :online, -> { where('contacted_at > ?', online_contact_time_deadline) } scope :online, -> { where('contacted_at > ?', online_contact_time_deadline) }
scope :recent, -> { where('ci_runners.created_at > :date OR ci_runners.contacted_at > :date', date: 3.months.ago) } scope :recent, -> { where('ci_runners.created_at > :date OR ci_runners.contacted_at > :date', date: 3.months.ago) }
# The following query using negation is cheaper than using `contacted_at <= ?` scope :offline, -> { where(arel_table[:contacted_at].lteq(online_contact_time_deadline)) }
# 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 :not_connected, -> { where(contacted_at: nil) } scope :not_connected, -> { where(contacted_at: nil) }
scope :ordered, -> { order(id: :desc) } scope :ordered, -> { order(id: :desc) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment