Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider expires_in when clear expired tokens with StaleRecordsCleaner #1690

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ User-visible changes worth mentioning.

## main

- [#PR ID] Add your changelog here.
- [#1690] Consider expires_in when clear expired tokens with StaleRecordsCleaner.

## 5.6.8

Expand Down
1 change: 1 addition & 0 deletions lib/doorkeeper/orm/active_record/stale_records_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def clean_expired(ttl)
@base_scope
.where.not(expires_in: nil)
.where(table[:created_at].lt(Time.current - ttl))
.where(table[:created_at] + table[:expires_in].lt(Time.current))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't we have an issues with timezones? I believe we're storing UTC and should use the same value regardless of configured application timezone, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I believe .where(table[:created_at].lt(Time.current - ttl)) does the same 🤔 By calculating ttl from configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nbulaj it does the same only if you rely on the ttl from configuration. If in your app your are creating tokens with different expiration times you need to consider expires_in and perform calculations with it.

.in_batches(&:delete_all)
end
end
Expand Down