Description
Every authenticated request triggers a MongoDB find_one + update_one round-trip to validate the API key and update last_used. This is the single biggest latency contributor for authenticated endpoints, adding roughly 30–80ms to every request.
Code Reference
src/database/api_key_store.py - validate_api_key()
Proposed Fix
Add an in-memory TTL cache (e.g. cachetools.TTLCache) keyed by key_hash.
Cache validated results for 60–300s.
Batch last_used updates in a background task instead of blocking the main request path.
Description
Every authenticated request triggers a MongoDB
find_one+update_oneround-trip to validate the API key and updatelast_used. This is the single biggest latency contributor for authenticated endpoints, adding roughly 30–80ms to every request.Code Reference
src/database/api_key_store.py-validate_api_key()Proposed Fix
Add an in-memory TTL cache (e.g. cachetools.TTLCache) keyed by
key_hash.Cache validated results for 60–300s.
Batch
last_usedupdates in a background task instead of blocking the main request path.