fix(ai-moderation): restrict vision cache pre-download check to stickers and custom emojis only

This commit is contained in:
MythEclipse
2026-06-04 17:20:52 +07:00
parent 5d9713b162
commit 269a13d96a
@@ -1282,22 +1282,6 @@ async function _runSingleMediaAnalysis(
return; return;
} }
// Check vision cache BEFORE downloading
const attVisionKey = makeImageCacheKey(urlToUse);
const cachedVision = await getCachedMediaAnalysis(attVisionKey);
if (cachedVision) {
log.debug(
{ attachmentId: att.id, cacheKey: attVisionKey },
"Vision cache HIT for attachment — skipped download",
);
const sourceLabel = `[gambar di atas adalah attachment ${att.filename} dari pesan id=${att.message_id}]`;
const analysisText = `[Media analysis for message ${att.message_id}] ${sourceLabel}: ${cachedVision}`;
const existing = mediaAnalysisMap.get(targetId) ?? [];
existing.push(analysisText);
mediaAnalysisMap.set(targetId, existing);
return;
}
const controller = new AbortController(); const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 15000); const timeoutId = setTimeout(() => controller.abort(), 15000);
@@ -1463,23 +1447,25 @@ async function _runSingleMediaAnalysis(
// Skip if we already have 8 images // Skip if we already have 8 images
if ((imageMap.get(targetId)?.length ?? 0) >= 8) return; if ((imageMap.get(targetId)?.length ?? 0) >= 8) return;
// Vision cache check before download // Vision cache check before download (sticker & emoji keys only, since
const visionCacheKey = candidate.customEmojiId // their cache keys are consistent between check and store — embed URLs
? makeCustomEmojiCacheKey(candidate.customEmojiId) // use base64 data URL keys that never match the CDN URL).
: candidate.stickerName if (candidate.customEmojiId || candidate.stickerName) {
? makeStickerCacheKey(candidate.stickerName) const visionCacheKey = candidate.customEmojiId
: makeImageCacheKey(candidate.url); ? makeCustomEmojiCacheKey(candidate.customEmojiId)
const cachedVision = await getCachedMediaAnalysis(visionCacheKey); : makeStickerCacheKey(candidate.stickerName!);
if (cachedVision) { const cachedVision = await getCachedMediaAnalysis(visionCacheKey);
log.debug( if (cachedVision) {
{ cacheKey: visionCacheKey }, log.debug(
"Vision cache HIT for media candidate — skipped download", { cacheKey: visionCacheKey },
); "Vision cache HIT for media candidate — skipped download",
const analysisText = `[Media analysis for message ${candidate.messageId}] ${candidate.label}: ${cachedVision}`; );
const existing = mediaAnalysisMap.get(targetId) ?? []; const analysisText = `[Media analysis for message ${candidate.messageId}] ${candidate.label}: ${cachedVision}`;
existing.push(analysisText); const existing = mediaAnalysisMap.get(targetId) ?? [];
mediaAnalysisMap.set(targetId, existing); existing.push(analysisText);
return; mediaAnalysisMap.set(targetId, existing);
return;
}
} }
// Sticker download cache // Sticker download cache