Skip to content

Add a rake task to clean expired access tokens #114

@hoangmirs

Description

@hoangmirs

Why

  • We're using Heroku Postgres - Mini which has the limitation of 10k records
  • Recently, the records have increased so quickly
  • We should add a task to clean the token table and run it everyday
namespace :token do
  desc "Clean expired tokens"
  task clean: :environment do
    delete_before = 1.days.ago
    expire = [
      "(revoked_at IS NOT NULL AND revoked_at < :delete_before) OR " +
      "(expires_in IS NOT NULL AND (created_at + expires_in * INTERVAL '1 second') < :delete_before)",
      { delete_before: delete_before }
    ]

    Doorkeeper::AccessToken.where(expire).delete_all
  end
end

Who Benefits?

Maintainers

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions