Sha256: cc33dce39a5434d5601992258c6a4cb3299b519c04dbe50406f46d3a4709546c

Contents?: true

Size: 830 Bytes

Versions: 32

Compression:

Stored size: 830 Bytes

Contents

# frozen_string_literal: true

module Doorkeeper
  module Orm
    module ActiveRecord
      # Helper class to clear stale and non-active tokens and grants.
      # Used by Doorkeeper Rake tasks.
      #
      class StaleRecordsCleaner
        def initialize(base_scope)
          @base_scope = base_scope
        end

        # Clears revoked records
        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

        # Clears expired records
        def clean_expired(ttl)
          table = @base_scope.arel_table

          @base_scope.where(table[:created_at].lt(Time.current - ttl))
            .in_batches(&:delete_all)
        end
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
doorkeeper-5.6.2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.6.1 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.6.0 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.6.0.rc2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.6.0.rc1 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.4 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.3 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.1 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.0 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.0.rc2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.1.2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.5.0.rc1 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.4.0 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.2.6 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.3.3 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.1.1 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.4.0.rc2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.2.5 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
doorkeeper-5.3.2 lib/doorkeeper/orm/active_record/stale_records_cleaner.rb