From 4d94d438ab65bdb9dbfadbbc03e73bfe2f08bdf6 Mon Sep 17 00:00:00 2001 From: Sulthan Zaki Date: Tue, 28 Jul 2026 06:56:18 +0700 Subject: [PATCH] fix(userscript): migrate cached and queued Asura keys on load --- userscript/manga-bookmark.user.js | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/userscript/manga-bookmark.user.js b/userscript/manga-bookmark.user.js index 3a5acb0..625ac0c 100644 --- a/userscript/manga-bookmark.user.js +++ b/userscript/manga-bookmark.user.js @@ -396,6 +396,38 @@ 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() { return queue.length; }