Class: Doorkeeper::Orm::ActiveRecord::StaleRecordsCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/doorkeeper/orm/active_record/stale_records_cleaner.rb

Overview

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

Instance Method Summary collapse

Constructor Details

#initialize(base_scope) ⇒ StaleRecordsCleaner

Returns a new instance of StaleRecordsCleaner.



10
11
12
# File 'lib/doorkeeper/orm/active_record/stale_records_cleaner.rb', line 10

def initialize(base_scope)
  @base_scope = base_scope
end

Instance Method Details

#clean_expired(ttl) ⇒ Object

Clears expired records



25
26
27
28
29
30
31
32
# 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_revokedObject

Clears revoked records



15
16
17
18
19
20
21
22
# 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