require "sequel"

class PendingJob < Sequel::Model
  unrestrict_primary_key

  def self.pending_query_ids
    ids = []

    db.transaction do
      ids = select_map(:query_id)
      filter(query_id: ids).delete
    end

    ids
  end
end

require "sequel"

class PendingJob < Sequel::Model
  unrestrict_primary_key

  def self.pending_query_ids
    ids = []

    db.transaction do
      ids = select_map(:query_id)
      filter(query_id: ids).delete if ids.any?
    end

    ids
  end
end

Reduce database load when checking for pending jobs
Reduce database load when checking for pending jobs
