Repository navigation
fix(bot): bound player track state with LRU + 30min TTL - #773
Conversation
Swap the three per-guild player-state Maps in trackHandlers (`lastPlayedTracks`, `guildTrackStartTimes`, `recentlyPlayedTracks`) to `LRUCache` with `max: MAX_GUILD_ENTRIES` and a 30-minute TTL with `updateAgeOnGet`. Matches the pattern already used in `utils/music/duplicateDetection/types.ts`. Prevents unbounded memory growth on long-running bot instances and drops the manual eviction block for `lastPlayedTracks` (LRU handles size + idle eviction). Manual per-guild list trim for `recentlyPlayedTracks` stays because each entry is a list whose size is independent of the cache's key count. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 33 minutes and 1 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
Swap the three per-guild player-state Maps in trackHandlers (`lastPlayedTracks`, `guildTrackStartTimes`, `recentlyPlayedTracks`) to `LRUCache` with `max: MAX_GUILD_ENTRIES` and a 30-minute TTL with `updateAgeOnGet`. Matches the pattern already used in `utils/music/duplicateDetection/types.ts`. Prevents unbounded memory growth on long-running bot instances and drops the manual eviction block for `lastPlayedTracks` (LRU handles size + idle eviction). Manual per-guild list trim for `recentlyPlayedTracks` stays because each entry is a list whose size is independent of the cache's key count. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>



Summary
Maps inpackages/bot/src/handlers/player/trackHandlers.ts(lastPlayedTracks,guildTrackStartTimes,recentlyPlayedTracks) toLRUCachewithmax: MAX_GUILD_ENTRIESand a 30-minute TTL (updateAgeOnGet: true).packages/bot/src/utils/music/duplicateDetection/types.ts—lru-cache ^10.4.3is already a@lucky/botdependency.lastPlayedTracks(LRU handles size + idle eviction). Keeps the per-guild list trim forrecentlyPlayedTracksbecause each entry is itself a list whose length is independent of the cache key count.Why
Long-running bot instances would grow these Maps without bound as guilds rotated through playback. LRU + TTL caps memory and evicts idle guilds after 30 min. Existing callers read these as
Map-compatible (.get,.set,.delete,.has,.entries()) —LRUCacheexposes the same API.Out of scope / follow-ups
duplicateDetection/types.tsexports identically-namedlastPlayedTracks/recentlyPlayedTracksas a separate LRU cache instance. Pre-existing duplication; consolidating the two is a larger refactor.tsc --noEmiterrors in@lucky/botare pre-existing onmain(reactionroleHandlers, applyPlan, guildMemberUpdate, interactionHandler, eventHandler, captureGuildState).Test plan
npx jest --testPathPatterns trackHandlers— 20/20 pass.🤖 Generated with Claude Code