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

Cache authtoken lookup by token #42823

Closed
ChristophWurst opened this issue Jan 16, 2024 · 0 comments · Fixed by #43057
Closed

Cache authtoken lookup by token #42823

ChristophWurst opened this issue Jan 16, 2024 · 0 comments · Fixed by #43057

Comments

@ChristophWurst
Copy link
Member

ChristophWurst commented Jan 16, 2024

How to use GitHub

  • Please use the 👍 reaction to show that you are interested into the same feature.
  • Please don't comment if you have no relevant information to add. It's just extra noise for everyone subscribed to this issue.
  • Subscribe to receive notifications on status change and new comments.

Is your feature request related to a problem? Please describe.

SELECT * FROM `oc_authtoken` WHERE (`token` = :dcValue1) AND (`version` = :dcValue2) is one of the most common queries in Nextcloud executed most requests.

Describe the solution you'd like

Cache the lookup

  1. Positive cache for rows that exist. Keep data in memory for a few seconds to eliminate database lookups for highly concurrent requests of one user.
    1. Keep TTL low enough to kill any connections when the token is deleted within reasonable time (30s?)
    2. For time-critical data, like the password, \OC\Authentication\Token\PublicKeyTokenProvider::getPassword could still fetch the latest version from the database, to avoid reading an outdated password. This might be debatable and we could accept some failing authentication on external storage etc. for the short period of time where the password changes.
  2. Negative cache for rows that do not exist. The tokens are random so it's very unlikely that a token that doesn't exist right now will exist in the next few minutes. Yet if a client retries their token again and again we hit the database for each request.

Describe alternatives you've considered

N/a

Additional context

N/a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants