Skip to content

Cleanup job removes not expired tokens #1688

@jensljungblad

Description

@jensljungblad

This is a follow-up to #1612 which was closed by #1625.

The PR fixed half of the problem. The issue is that the rake task doorkeeper:db:cleanup:expired_tokens will still delete tokens which haven't yet expired. The reason is that the expires_in column is not considered.

Compare the logic in

class StaleRecordsCleaner
  # This method compares against `created_at`
  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
end

With

module Expirable
  # This method compares against `expires_at`
  def expired?
    !!(expires_in && Time.now.utc > expires_at)
  end
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions