access_tokens_vacuum.rb 745 B

1234567891011121314151617181920
  1. # frozen_string_literal: true
  2. class Vacuum::AccessTokensVacuum
  3. def perform
  4. vacuum_revoked_access_tokens!
  5. vacuum_revoked_access_grants!
  6. end
  7. private
  8. def vacuum_revoked_access_tokens!
  9. Doorkeeper::AccessToken.where.not(expires_in: nil).where('created_at + make_interval(secs => expires_in) < NOW()').in_batches.delete_all
  10. Doorkeeper::AccessToken.where.not(revoked_at: nil).where('revoked_at < NOW()').in_batches.delete_all
  11. end
  12. def vacuum_revoked_access_grants!
  13. Doorkeeper::AccessGrant.where.not(expires_in: nil).where('created_at + make_interval(secs => expires_in) < NOW()').in_batches.delete_all
  14. Doorkeeper::AccessGrant.where.not(revoked_at: nil).where('revoked_at < NOW()').in_batches.delete_all
  15. end
  16. end