Add detailed cache logging
This commit is contained in:
parent
ed67770a1a
commit
0ff34e4963
1 changed files with 8 additions and 1 deletions
|
@ -36,17 +36,22 @@ class CustomerTermBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
_loadCache() {
|
_loadCache() {
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] Loading cache from ${this._cacheFile.path}`);
|
||||||
try {
|
try {
|
||||||
if (this._cacheFile.exists()) {
|
if (this._cacheFile.exists()) {
|
||||||
let stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
|
let stream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(Ci.nsIFileInputStream);
|
||||||
stream.init(this._cacheFile, -1, 0, 0);
|
stream.init(this._cacheFile, -1, 0, 0);
|
||||||
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
let data = NetUtil.readInputStreamToString(stream, stream.available());
|
||||||
stream.close();
|
stream.close();
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] Cache file contents: ${data}`);
|
||||||
let obj = JSON.parse(data);
|
let obj = JSON.parse(data);
|
||||||
for (let [k, v] of Object.entries(obj)) {
|
for (let [k, v] of Object.entries(obj)) {
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] ⮡ Loaded entry '${k}' → ${v}`);
|
||||||
this.cache.set(k, v);
|
this.cache.set(k, v);
|
||||||
}
|
}
|
||||||
console.log(`[ai-filter][ExpressionSearchFilter] Loaded ${this.cache.size} cache entries`);
|
console.log(`[ai-filter][ExpressionSearchFilter] Loaded ${this.cache.size} cache entries`);
|
||||||
|
} else {
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] Cache file does not exist`);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`[ai-filter][ExpressionSearchFilter] Failed to load cache`, e);
|
console.error(`[ai-filter][ExpressionSearchFilter] Failed to load cache`, e);
|
||||||
|
@ -54,9 +59,11 @@ class CustomerTermBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
_saveCache() {
|
_saveCache() {
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] Saving cache to ${this._cacheFile.path}`);
|
||||||
try {
|
try {
|
||||||
let obj = Object.fromEntries(this.cache);
|
let obj = Object.fromEntries(this.cache);
|
||||||
let data = JSON.stringify(obj);
|
let data = JSON.stringify(obj);
|
||||||
|
console.log(`[ai-filter][ExpressionSearchFilter] Cache data to write: ${data}`);
|
||||||
let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
|
let stream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
|
||||||
stream.init(this._cacheFile,
|
stream.init(this._cacheFile,
|
||||||
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
|
FileUtils.MODE_WRONLY | FileUtils.MODE_CREATE | FileUtils.MODE_TRUNCATE,
|
||||||
|
@ -236,7 +243,7 @@ class ClassificationTerm extends CustomerTermBase {
|
||||||
const obj = JSON.parse(cleanedText);
|
const obj = JSON.parse(cleanedText);
|
||||||
matched = obj.matched === true || obj.match === true;
|
matched = obj.matched === true || obj.match === true;
|
||||||
|
|
||||||
console.log(`[ai-filter][ExpressionSearchFilter] Caching:`, key);
|
console.log(`[ai-filter][ExpressionSearchFilter] Caching entry '${key}' → ${matched}`);
|
||||||
this.cache.set(key, matched);
|
this.cache.set(key, matched);
|
||||||
this._saveCache();
|
this._saveCache();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue