← back to Yolo Agent Tasks Staging
04_wallco_compare_stats.md
26 lines
Work on ~/Projects/wallco-ai. /compare already has ETag short-circuit. Add hit counter.
TASK: Compare-ETag stats in /admin/health.
Add `const _compareStats = { hits: 0, misses: 0, since: Date.now() };` next to the existing _byColorStats / _randomStats vars.
In the /compare route handler:
- Increment `_compareStats.hits++` right before the 304 return (in the `if (req.headers['if-none-match'] === _cmpEtag)` branch)
- Increment `_compareStats.misses++` after the ETag check passes (when actually rendering)
In /admin/health, add a `compare_etag` block parallel to `random_etag`:
```js
compare_etag: (() => {
const t = _compareStats.hits + _compareStats.misses;
return { hits: _compareStats.hits, misses: _compareStats.misses,
hit_rate: t > 0 ? Math.round((_compareStats.hits / t) * 1000) / 10 : null,
since: new Date(_compareStats.since).toISOString() };
})(),
```
Smoke: fire /compare?ids=14,72 twice (second with INM header from the 1st response), then `curl /admin/health | node -e 'const j=JSON.parse(require("fs").readFileSync(0,"utf8"));console.log(j.compare_etag)'` — should show hits=1, misses=1, hit_rate=50.
Commit: `/admin/health: compare-ETag hit/miss stats (parallel to random_etag and by_color_cache)`
Reload via pm2.