Expensive database aggregations run on every request without caching
warningperformanceUpdated Nov 4, 2024(via Exa)
Sources
Technologies:
How to detect:
Stats calculations across entire database (4+ years of data) execute on every page load, contributing multi-second delays for data that changes infrequently
Recommended action:
Implement time-based caching with TTL (e.g., 24 hours for totals/stats). Options: functools.lru_cache (call-count based), cachetools (time-based), or simple JSON file cache. Check cache freshness before recalculating. For uWSGI multi-process deployments, prefer file-based or external cache over in-memory.