fix(userscript): migrate cached and queued Asura keys on load

This commit is contained in:
2026-07-28 06:56:18 +07:00
parent 3a2210b9c8
commit 4d94d438ab
+32
View File
@@ -396,6 +396,38 @@
const queue = loadQueue(); const queue = loadQueue();
// Keys cached (or parked in the retry queue) by versions before the
// Asura build-hash strip still carry the hash. Align them with the
// server-side migration so a queued PUT cannot resurrect an orphaned
// row and the cache matches what the server now returns. Duplicate
// cache entries collapsing onto one key are left as-is — the next
// refresh() replaces the whole list from the already-merged server.
(function migrateLocalKeys() {
let dirty = false;
for (let i = 0; i < state.list.length; i++) {
const b = state.list[i];
if (b.site !== "asura" || !b.series_id) continue;
const id = stripBuildHash(b.series_id);
if (id === b.series_id) continue;
state.list[i] = Object.assign({}, b, { series_id: id, key: "asura:" + id });
dirty = true;
}
if (dirty) {
reindex();
saveCache(state.list);
}
dirty = false;
for (const e of queue) {
if (!e.key.startsWith("asura:")) continue;
const k = "asura:" + stripBuildHash(e.key.slice("asura:".length));
if (k !== e.key) {
e.key = k;
dirty = true;
}
}
if (dirty) saveQueue(queue);
})();
function queueCount() { function queueCount() {
return queue.length; return queue.length;
} }