Use Message-ID for cache keys
This commit is contained in:
parent
41a0f4f8f2
commit
8ba2a931b9
3 changed files with 21 additions and 6 deletions
|
@ -62,7 +62,7 @@ text extracted from all text parts.
|
||||||
### Cache Strategy
|
### Cache Strategy
|
||||||
|
|
||||||
`aiCache` persists classification results. Each key is the SHA‑256 hex of
|
`aiCache` persists classification results. Each key is the SHA‑256 hex of
|
||||||
`"<message id>|<criterion>"` and maps to an object with `matched` and `reason`
|
`"<message Message-ID>|<criterion>"` and maps to an object with `matched` and `reason`
|
||||||
properties. Any legacy `aiReasonCache` data is merged into `aiCache` the first
|
properties. Any legacy `aiReasonCache` data is merged into `aiCache` the first
|
||||||
time the add-on loads after an update.
|
time the add-on loads after an update.
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ message meets a specified criterion.
|
||||||
### Cache Storage
|
### Cache Storage
|
||||||
|
|
||||||
Classification results are stored under the `aiCache` key in extension storage.
|
Classification results are stored under the `aiCache` key in extension storage.
|
||||||
Each entry maps a SHA‑256 hash of `"<message id>|<criterion>"` to an object
|
Each entry maps a SHA‑256 hash of `"<message Message-ID>|<criterion>"` to an object
|
||||||
containing `matched` and `reason` fields. Older installations with a separate
|
containing `matched` and `reason` fields. Older installations with a separate
|
||||||
`aiReasonCache` will be migrated automatically on startup.
|
`aiReasonCache` will be migrated automatically on startup.
|
||||||
|
|
||||||
|
|
|
@ -76,11 +76,26 @@ function buildCacheKeySync(id, criterion) {
|
||||||
return sha256HexSync(`${id}|${criterion}`);
|
return sha256HexSync(`${id}|${criterion}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildCacheKey(id, criterion) {
|
async function resolveHeaderId(id) {
|
||||||
if (Services) {
|
if (typeof id === "number" && typeof messenger?.messages?.get === "function") {
|
||||||
return buildCacheKeySync(id, criterion);
|
try {
|
||||||
|
const hdr = await messenger.messages.get(id);
|
||||||
|
if (hdr?.headerMessageId) {
|
||||||
|
return hdr.headerMessageId;
|
||||||
}
|
}
|
||||||
return sha256Hex(`${id}|${criterion}`);
|
} catch (e) {
|
||||||
|
aiLog(`Failed to resolve headerMessageId for ${id}`, { level: 'warn' }, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function buildCacheKey(id, criterion) {
|
||||||
|
const resolvedId = await resolveHeaderId(id);
|
||||||
|
if (Services) {
|
||||||
|
return buildCacheKeySync(resolvedId, criterion);
|
||||||
|
}
|
||||||
|
return sha256Hex(`${resolvedId}|${criterion}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadCache() {
|
async function loadCache() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue