fix(stats): pass maxEntries to cache.set to enable LRU eviction - #39
Conversation
The /stats route was calling cache.set(key, data) without the maxEntries argument. Inside evictLruIfNeeded, the comparison `this.store.size < undefined` evaluates to false (NaN), so the function always evicted the oldest entry on every cache miss instead of skipping eviction when below the limit. This silently displaced /elo and /streak entries from the shared cache, defeating the maxEntries=200 budget. Other routes (elo.js, streak.js) already pass config.cache.maxEntries. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe ChangesStats Cache Size Limit
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
src/routes/stats.jschamavacache.set(key, data)sem o argumentomaxEntries. Dentro deevictLruIfNeeded, a comparaçãothis.store.size < undefinedresolve parafalse(NaN), então a função sempre eviccionava a entrada mais antiga em cada cache miss, ao invés de pular a eviction quando abaixo do limite./statsderrubava silenciosamente uma entrada de/eloou/streakdo cache compartilhado, anulando o budget demaxEntries=200.elo.js:62,streak.js:62) já passavamconfig.cache.maxEntriescorretamente — esta mudança alinhastats.jscom o mesmo padrão.Test plan
npm starte bater/stats?player=<nick>algumas vezesstatsTtl(3 min)/eloe/streaknão são mais evictadas em cada chamada de/stats🤖 Generated with Claude Code
Summary by CodeRabbit