class Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner

Helper class to clear stale and non-active tokens and grants. Used by Doorkeeper Rake tasks.

Public Class Methods

new(base_scope) click to toggle source
# File lib/doorkeeper/orm/active_record/stale_records_cleaner.rb, line 10
def initialize(base_scope)
  @base_scope = base_scope
end

Public Instance Methods

clean_expired(ttl) click to toggle source

Clears expired records

# File lib/doorkeeper/orm/active_record/stale_records_cleaner.rb, line 25
def clean_expired(ttl)
  table = @base_scope.arel_table

  @base_scope
    .where.not(expires_in: nil)
    .where(table[:created_at].lt(Time.current - ttl))
    .in_batches(&:delete_all)
end
clean_revoked() click to toggle source

Clears revoked records

# File lib/doorkeeper/orm/active_record/stale_records_cleaner.rb, line 15
def clean_revoked
  table = @base_scope.arel_table

  @base_scope
    .where.not(revoked_at: nil)
    .where(table[:revoked_at].lt(Time.current))
    .in_batches(&:delete_all)
end