Browse Source

fix: removing scripts from recycle bin

fixes #1754
tophf 2 years ago
parent
commit
713ddbcb1a
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/background/utils/db.js

+ 6 - 7
src/background/utils/db.js

@@ -453,20 +453,19 @@ function getSizeForResources(accum, url) {
 }
 
 export async function removeScripts(ids) {
+  const idsToRemove = [];
   // Only those marked as removed can be removed permanently
   const newLen = 1 + removedScripts.reduce((iAlive, script, i) => {
     const id = getPropsId(script);
-    if (ids.includes(id)) delete scriptMap[id];
-    else if (++iAlive < i) removedScripts[iAlive] = script;
+    if (ids.includes(id)) {
+      idsToRemove.push(S_CODE_PRE + id, S_SCRIPT_PRE + id, S_VALUE_PRE + id);
+      delete scriptMap[id];
+    } else if (++iAlive < i) removedScripts[iAlive] = script;
     return iAlive;
   }, -1);
   if (removedScripts.length !== newLen) {
     removedScripts.length = newLen; // live scripts were moved to the beginning
-    await storage.base.remove([
-      ...ids.map(storage[S_CODE].toKey),
-      ...ids.map(storage[S_SCRIPT].toKey),
-      ...ids.map(storage[S_VALUE].toKey),
-    ]);
+    await storage.base.remove(idsToRemove);
     return sendCmd('RemoveScripts', ids);
   }
 }