-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
fix: add index on requested_at for refresh tokens and use it in janitor #3516
fix: add index on requested_at for refresh tokens and use it in janitor #3516
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3516 +/- ##
==========================================
- Coverage 76.89% 76.85% -0.05%
==========================================
Files 124 124
Lines 9102 9175 +73
==========================================
+ Hits 6999 7051 +52
- Misses 1660 1673 +13
- Partials 443 451 +8
|
May I suggest adding nid as the index as well, given that it's part of the query in question? |
@aeneasr Do you mean as a separate index or part of the
The composite one was suggested by @arnolf here #3115 (comment) |
Like below :) |
@aeneasr Please have a look, I fixed the index. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
Thanks for the contribution!
Related issue(s)
Inspired by #3115
This change addresses the performance issue with Hydra Janitor, which makes the cleanups extremely slow due to inefficient query that leads to a full table scan.
The approach here is taken from the issue above. Adding an index on the
requested_at
field and ordering by it in Janitor avoids full table scan and improves the performance of the cleanups.Checklist
introduces a new feature.
contributing code guidelines.
vulnerability. If this pull request addresses a security vulnerability, I
confirm that I got the approval (please contact
security@ory.sh) from the maintainers to push
the changes.
works.
Further Comments
When we run the following query:
We get the following plan, with an execution time of 2.6 seconds. So 2,6 seconds to delete 100 refresh tokens. We can note here that there is a very high cost of the index scan with a lot of filtered rows.
Just to confirm, we also checked the distribution of refresh tokens over the dates, but looks good:
To resolve the issue, we applied an index to the refresh token table:
When we now try to run the cleanup query, and instead change the order by from signature to requested_at
We get a much more healthy execution with 720 hours interval: