Handle cache loading without Services
This commit is contained in:
parent
a154029320
commit
bf2743d131
1 changed files with 11 additions and 1 deletions
|
@ -168,7 +168,14 @@ function buildPrompt(body, criterion) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCachedResult(cacheKey) {
|
function getCachedResult(cacheKey) {
|
||||||
|
if (!gCacheLoaded) {
|
||||||
|
if (Services?.tm?.spinEventLoopUntil) {
|
||||||
loadCacheSync();
|
loadCacheSync();
|
||||||
|
} else {
|
||||||
|
// In non-privileged contexts we can't block, so bail out early.
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cacheKey && gCache.has(cacheKey)) {
|
if (cacheKey && gCache.has(cacheKey)) {
|
||||||
aiLog(`[AiClassifier] Cache hit for key: ${cacheKey}`, {debug: true});
|
aiLog(`[AiClassifier] Cache hit for key: ${cacheKey}`, {debug: true});
|
||||||
return gCache.get(cacheKey);
|
return gCache.get(cacheKey);
|
||||||
|
@ -244,6 +251,9 @@ function classifyTextSync(text, criterion, cacheKey = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function classifyText(text, criterion, cacheKey = null) {
|
async function classifyText(text, criterion, cacheKey = null) {
|
||||||
|
if (!gCacheLoaded) {
|
||||||
|
await loadCache();
|
||||||
|
}
|
||||||
const cached = getCachedResult(cacheKey);
|
const cached = getCachedResult(cacheKey);
|
||||||
if (cached !== null) {
|
if (cached !== null) {
|
||||||
return cached;
|
return cached;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue