From bf2743d131eb60875084c404381dd6730e34fcc6 Mon Sep 17 00:00:00 2001 From: Jordan Wages Date: Wed, 25 Jun 2025 22:09:15 -0500 Subject: [PATCH] Handle cache loading without Services --- modules/AiClassifier.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/AiClassifier.js b/modules/AiClassifier.js index fbb0a36..4c966d9 100644 --- a/modules/AiClassifier.js +++ b/modules/AiClassifier.js @@ -168,7 +168,14 @@ function buildPrompt(body, criterion) { } function getCachedResult(cacheKey) { - loadCacheSync(); + if (!gCacheLoaded) { + if (Services?.tm?.spinEventLoopUntil) { + loadCacheSync(); + } else { + // In non-privileged contexts we can't block, so bail out early. + return null; + } + } if (cacheKey && gCache.has(cacheKey)) { aiLog(`[AiClassifier] Cache hit for key: ${cacheKey}`, {debug: true}); return gCache.get(cacheKey); @@ -244,6 +251,9 @@ function classifyTextSync(text, criterion, cacheKey = null) { } async function classifyText(text, criterion, cacheKey = null) { + if (!gCacheLoaded) { + await loadCache(); + } const cached = getCachedResult(cacheKey); if (cached !== null) { return cached;