diff --git a/services/discord-gateway/src/modules/ai-moderation/stickerCache.ts b/services/discord-gateway/src/modules/ai-moderation/stickerCache.ts index eb151b3..36c5729 100644 --- a/services/discord-gateway/src/modules/ai-moderation/stickerCache.ts +++ b/services/discord-gateway/src/modules/ai-moderation/stickerCache.ts @@ -75,7 +75,7 @@ export async function getStickerFromCache( const key = sanitizeKey(stickerName); try { const row = await executeGet( - "SELECT base64, mime_type, size, fetched_at FROM sticker_cache WHERE name = ? AND fetched_at > ?", + "SELECT base64, mime_type, size, fetched_at FROM sticker_cache WHERE name = $1 AND fetched_at > $2", [key, Date.now() - TTL_MS], ); if (!row) return null; @@ -110,7 +110,7 @@ export async function setStickerInCache( await evictIfNeeded(size); await executeAll( `INSERT INTO sticker_cache (name, base64, mime_type, size, fetched_at) - VALUES (?, ?, ?, ?, ?) + VALUES ($1, $2, $3, $4, $5) ON CONFLICT (name) DO UPDATE SET base64 = EXCLUDED.base64, mime_type = EXCLUDED.mime_type, diff --git a/services/discord-gateway/src/modules/ai-moderation/textCacheStore.ts b/services/discord-gateway/src/modules/ai-moderation/textCacheStore.ts index 241de36..cb28dfc 100644 --- a/services/discord-gateway/src/modules/ai-moderation/textCacheStore.ts +++ b/services/discord-gateway/src/modules/ai-moderation/textCacheStore.ts @@ -269,6 +269,7 @@ export function makeUserModerationCacheKey( export async function getCachedUserModeration( cacheKey: string, ): Promise<{ + status: "clean" | "flagged"; flags: string[]; score: number; analysis: string; @@ -288,9 +289,19 @@ export async function getCachedUserModeration( if (!row) return null; const parsed = JSON.parse(row.flags) as Record; + const flags = (parsed.flags as string[]) ?? []; + // Use stored status if available (new entries), otherwise derive from flags (legacy compatibility) + const storedStatus = parsed.status as string | undefined; + const status: "clean" | "flagged" = + storedStatus === "clean" || storedStatus === "flagged" + ? storedStatus + : flags.length === 0 + ? "clean" + : "flagged"; return { - flags: (parsed.flags as string[]) ?? [], + status, + flags, score: (parsed.score as number) ?? 0, analysis: (parsed.analysis as string) ?? "", categories: (parsed.categories as string[]) ?? [],