feat: expand Redis caching across bot API routes and web dashboard#346
feat: expand Redis caching across bot API routes and web dashboard#346BillChirico merged 8 commits intomainfrom
Conversation
|
🚅 Deployed to the volvox-bot-pr-346 environment in volvox-bot
|
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
@coderabbitai review |
…e, fix comment precision, guard concurrent interval flushes
…concurrent interval flushes, sync lockfiles
… add AI-conversation fallback, fix test mock order, fix lint
f413ddc to
07f4119
Compare
| diff: | ||
| specifier: ^8.0.4 | ||
| version: 8.0.4 | ||
| specifier: ^8.0.3 | ||
| version: 8.0.3 | ||
| framer-motion: | ||
| specifier: ^12.38.0 | ||
| version: 12.38.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4) | ||
| lucide-react: | ||
| specifier: ^1.6.0 | ||
| version: 1.6.0(react@19.2.4) | ||
| specifier: ^0.577.0 | ||
| version: 0.577.0(react@19.2.4) | ||
| next: | ||
| specifier: ^16.2.1 | ||
| version: 16.2.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4) | ||
| specifier: ^16.2.0 | ||
| version: 16.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4) | ||
| next-auth: | ||
| specifier: ^4.24.13 | ||
| version: 4.24.13(next@16.2.1(react-dom@19.2.4(react@19.2.4))(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4) | ||
| version: 4.24.13(next@16.2.0(react-dom@19.2.4(react@19.2.4))(react@19.2.4))(react-dom@19.2.4(react@19.2.4))(react@19.2.4) | ||
| next-themes: |
There was a problem hiding this comment.
web/package.json pins deps like next: ^16.2.1, lucide-react: ^1.6.0, diff: ^8.0.4, and includes simple-icons, but web/pnpm-lock.yaml now records different specifiers/versions (e.g. next ^16.2.0, lucide-react ^0.577.0, diff ^8.0.3) and has no simple-icons entry. With pnpm install --frozen-lockfile this will fail. Please regenerate/revert the web lockfile so it matches web/package.json (or commit the corresponding web/package.json changes if the downgrade/removal was intentional).
|
@claude review |
a485be8 to
11e95ce
Compare
- engagement.js: add MAX_BUFFER_SIZE (50k) with backpressure, batch inserts (BATCH_SIZE 10k), in-flight guard to prevent overlapping flushes, rate-limited error logging (1st + every 30th), fix comment (FLUSH_INTERVAL_MS -> DEFAULT_FLUSH_INTERVAL_MS), rethrow on flush failure - guilds.js: validate channelId as snowflake (digits, max 20 chars) before cache key, wrap activeAiConversations query in try/catch with null fallback - moderation.js: use dedicated TTL.MOD_STATS instead of TTL.LEADERBOARD - cache.js: add TTL.MOD_STATS, add bot:stats:* to cacheClear() prefixes - guilds.test.js: fix mock sequence for moved activeAiConversations query, update channelId fixtures to valid snowflakes - reviewHandler.test.js: fix flatMapIdentity lint (biome)
a76aaa1 to
088f931
Compare
|
| const messageAuthor = reaction.message.author; | ||
| const authorId = messageAuthor?.id; | ||
| if (authorId && authorId !== user.id && !messageAuthor?.bot) { | ||
| const authorEntry = getOrCreateEntry(guildId, authorId); |
There was a problem hiding this comment.
getOrCreateEntry() can return null when the buffer hits MAX_BUFFER_SIZE, but trackReaction() unconditionally dereferences authorEntry. If the buffer is at capacity and the reaction author entry is new, this will throw and can break event handling. Guard the author path the same way as the reactor path (only increment when an entry was created).
| const authorEntry = getOrCreateEntry(guildId, authorId); | |
| const authorEntry = getOrCreateEntry(guildId, authorId); | |
| if (!authorEntry) return; |
| * | ||
| * @param {string} guildId | ||
| * @param {string} userId | ||
| * @returns {StatsEntry} |
There was a problem hiding this comment.
The JSDoc for getOrCreateEntry() says @returns {StatsEntry}, but the function returns null when the buffer is full. Update the return type in the doc (and any related annotations) to reflect StatsEntry | null so callers and tooling don’t assume it’s always non-null.
| * @returns {StatsEntry} | |
| * @returns {StatsEntry | null} |
| @@ -522,8 +522,8 @@ packages: | |||
| resolution: {integrity: sha512-y4UPwWhH6vChKRkGdMB4odasUbHOUwy7KL+OVwF86PvT6QVOwElx+TiI1/6kcmcEe+g5YRXJFiXSXUdabqZOvQ==} | |||
| engines: {node: '>=16.11.0'} | |||
|
|
|||
| '@discordjs/rest@2.6.1': | |||
| resolution: {integrity: sha512-wwQdgjeaoYFiaG+atbqx6aJDpqW7JHAo0HrQkBTbYzM3/PJ3GweQIpgElNcGZ26DCUOXMyawYd0YF7vtr+fZXg==} | |||
| '@discordjs/rest@2.6.0': | |||
| resolution: {integrity: sha512-RDYrhmpB7mTvmCKcpj+pc5k7POKszS4E2O9TYc+U+Y4iaCP+r910QdO43qmpOja8LRr1RJ0b3U+CqVsnPqzf4w==} | |||
There was a problem hiding this comment.
pnpm-lock.yaml shows a broad set of transitive version changes (including downgrades like @discordjs/*) without any corresponding package.json change in this PR. Please confirm this lockfile churn is intentional and generated with the repo’s pinned pnpm version; otherwise, consider reverting the lockfile changes to keep the PR focused and reduce the risk of unintended dependency regressions.


engagement.js—trackMessageandtrackReactionnow synchronously increment in-memory counters;flushEngagementBuffer()batch-upserts all accumulated rows in a singleINSERT … ON CONFLICTevery 10 sisOptedOut()already uses an in-memory Set loaded once at startup — zero DB hit per call, no changes neededisSpam()/checkLinks()/ role-reward lookups are regex/config-only with no per-message DB queries — no changes neededstartEngagementFlushInterval()intostartup()(alongside other DB-backed schedulers) andstopEngagementFlushInterval()intogracefulShutdown()before the DB pool closestests/modules/engagement.test.jsfor the buffered API (26 tests covering buffer accumulation, batch SQL, bumpDays semantics, error recovery, interval lifecycle)pnpm lintpasses (13 pre-existing web warnings only)💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.