kkfluous
|
c02c1aa62c
|
perf(energy): add 60s TTL cache for all 4 endpoints
Hydrogen overview was 1.8-2.0s (3 full-table aggregations on 66K rows).
With cache: cold 1 user/min eats the full query, all subsequent within
60s window return in ~10ms.
Implementation:
- New cache.ts with cached(key, loader) helper
- Per-key in-flight de-duplication: concurrent requests share one loader
- Each handler wrapped, cache key includes query params
(e.g. "hydrogen/daily?range=last30&customer=external")
- TTL 60s as requested
Measured speedups:
- hydrogen/overview: 1.96s → 12ms (165x)
- hydrogen/daily: 270ms → 11ms (24x)
- electric/overview: 93ms → 9ms (10x)
- electric/monthly: 36ms → 9ms (4x)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
2026-04-28 17:50:48 +08:00 |
|