chore(discord-gateway): remove stale eslint-disable comment for sticker cache stats

This commit is contained in:
MythEclipse
2026-06-02 22:20:46 +07:00
parent c80a344391
commit bf6ec728c4
4 changed files with 38 additions and 25 deletions
@@ -1,3 +1,4 @@
import { createChildLogger } from "@bete/shared/logger";
import { Client } from "discord.js-selfbot-v13";
import { startPendingAIAnalysisWorker } from "../modules/ai-moderation/aiAnalyzer.js";
import { CommandHandler } from "../modules/command-handler/commandHandler.js";
@@ -17,7 +18,6 @@ import {
} from "../shared/database/drizzle.js";
import { runMigrations } from "../shared/database/migrate.js";
import { createDiscordClientOptions } from "../shared/discord/clientOptions.js";
import { createChildLogger } from "@bete/shared/logger";
import { createGracefulShutdown } from "./shutdown.js";
const logger = createChildLogger("discord-gateway");
@@ -1,11 +1,11 @@
import { existsSync } from "node:fs";
import { fileURLToPath } from "node:url";
import { createChildLogger } from "@bete/shared/logger";
import { retryWithBackoff } from "@bete/shared/utils";
import type { Client } from "discord.js-selfbot-v13";
import { AbortError } from "p-retry";
import { Piscina } from "piscina";
import { config } from "../../shared/config/config.js";
import { createChildLogger } from "@bete/shared/logger";
import { retryWithBackoff } from "@bete/shared/utils";
import type { EventBroadcaster } from "../event-broadcaster/index.js";
import { invalidateAnalyticsCache } from "../message-capture/analyticsStore.js";
import { isAgeRestrictedMetadata } from "../message-capture/messageMetadata.js";
@@ -28,9 +28,7 @@ import type {
import { attemptAutoDeleteFlaggedMessage } from "./autoDeleteManager.js";
import { buildConversationContext } from "./conversationContext.js";
import { runModerationAnalysis } from "./llmModerationClient.js";
import {
logModerationError,
} from "./responseLogger.js";
import { logModerationError } from "./responseLogger.js";
const logger = createChildLogger("ai-analyzer");
@@ -163,7 +161,8 @@ const MAX_CONSECUTIVE_ERRORS = 5;
const CONVERSATION_CB_COOLDOWN_MS = 60000;
function recordConversationBatchFailure(conversationKey: string): void {
const nextCount = (conversationConsecutiveErrors.get(conversationKey) ?? 0) + 1;
const nextCount =
(conversationConsecutiveErrors.get(conversationKey) ?? 0) + 1;
conversationConsecutiveErrors.set(conversationKey, nextCount);
if (nextCount >= MAX_CONSECUTIVE_ERRORS) {
@@ -471,11 +470,16 @@ async function processIndividualFallback(
lastError = error instanceof Error ? error.message : String(error);
// Log error with responseLogger
logModerationError([messageId], config.AI_LLM_MODEL, error as Error | string, {
phase: "individual_fallback",
conversationKey,
exhaustedOnIncomplete,
});
logModerationError(
[messageId],
config.AI_LLM_MODEL,
error as Error | string,
{
phase: "individual_fallback",
conversationKey,
exhaustedOnIncomplete,
},
);
// Infinite-loop prevention: if all retries were exhausted because the LLM
// consistently dropped this specific message (not a transient error),
@@ -1,9 +1,9 @@
import { createChildLogger } from "@bete/shared/logger";
import { retryWithBackoff } from "@bete/shared/utils";
import type { ChatCompletion } from "openai/resources/chat/completions";
import { AbortError } from "p-retry";
import { z } from "zod";
import { config } from "../../shared/config/config.js";
import { createChildLogger } from "@bete/shared/logger";
import { retryWithBackoff } from "@bete/shared/utils";
import { resizeImageForVision } from "../attachment-upload/imageResizer.js";
import { extractMessageMediaEvidence } from "../message-capture/messageMetadata.js";
import type {
@@ -532,7 +532,10 @@ const analyzeSingleMediaImage = async (
// processing this exact image, wait for it instead of starting a duplicate.
const existing = inFlightVisionCalls.get(cacheKey);
if (existing) {
log.debug({ cacheKey }, "Media analysis in-flight dedupe — waiting for existing call");
log.debug(
{ cacheKey },
"Media analysis in-flight dedupe — waiting for existing call",
);
const result = await existing;
if (!result) return null;
return `[Media analysis for message ${messageId}] ${image.sourceLabel}: ${result}`;
@@ -910,7 +913,15 @@ async function runTextOnlyBatch(
}),
])) as { results: AnalysisResult[]; raw: unknown };
const rawUsage = (batchResult.raw as { usage?: { prompt_tokens: number; completion_tokens: number; total_tokens: number } })?.usage;
const rawUsage = (
batchResult.raw as {
usage?: {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
};
}
)?.usage;
allResults.push(...batchResult.results);
if (batchResult.raw) lastRaw = batchResult.raw;
@@ -1,5 +1,5 @@
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
import { createChildLogger } from "@bete/shared/logger";
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
const logger = createChildLogger("sticker-cache");
@@ -42,10 +42,9 @@ export async function initStickerCache(): Promise<void> {
`CREATE INDEX IF NOT EXISTS "idx_sticker_cache_fetched_at" ON "sticker_cache" USING btree ("fetched_at")`,
);
await executeAll(
"DELETE FROM sticker_cache WHERE fetched_at < $1",
[Date.now() - TTL_MS],
);
await executeAll("DELETE FROM sticker_cache WHERE fetched_at < $1", [
Date.now() - TTL_MS,
]);
const row = await executeGet(
"SELECT count(*) as cnt, COALESCE(SUM(size), 0) as total FROM sticker_cache",
[],
@@ -149,10 +148,9 @@ async function evictIfNeeded(newSize: number): Promise<void> {
if (freed >= targetToFree) break;
}
await executeAll(
`DELETE FROM sticker_cache WHERE name = ANY($1)`,
[namesToDelete],
);
await executeAll(`DELETE FROM sticker_cache WHERE name = ANY($1)`, [
namesToDelete,
]);
statsCache.totalSizeBytes -= freed;
statsCache.entryCount -= namesToDelete.length;