gitlab-org--gitlab-foss/app/controllers/admin/jobs_controller.rb
Stan Hu 00709a13a4 Fix /admin/jobs failing to load due to statement timeout
The `ORDER BY created_at DESC` clause causes a sequential scan because
there is no index on the `created_at` column. We can sort by `id`
or by `updated_at` to make things fast.

Closes #49767
2018-07-30 10:03:05 -07:00

25 lines
589 B
Ruby

class Admin::JobsController < Admin::ApplicationController
def index
@scope = params[:scope]
@all_builds = Ci::Build
@builds = @all_builds.order('id DESC')
@builds =
case @scope
when 'pending'
@builds.pending.reverse_order
when 'running'
@builds.running.reverse_order
when 'finished'
@builds.finished
else
@builds
end
@builds = @builds.page(params[:page]).per(30)
end
def cancel_all
Ci::Build.running_or_pending.each(&:cancel)
redirect_to admin_jobs_path, status: :see_other
end
end