diff --git a/package.json b/package.json index 9135305..3670cd3 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "http-status-codes": "^2.3.0", "localforage": "^1.10.0", "localforage-getitems": "^1.4.2", + "localforage-removeitems": "^1.4.0", "lodash": "^4.17.21", "lucide": "^0.376.1", "mime-types": "^2.1.35", diff --git a/src/localdb.ts b/src/localdb.ts index b518646..377ef48 100644 --- a/src/localdb.ts +++ b/src/localdb.ts @@ -1,6 +1,8 @@ import localforage from "localforage"; -import { extendPrototype } from "localforage-getitems"; -extendPrototype(localforage); +import { extendPrototype as ep1 } from "localforage-getitems"; +import { extendPrototype as ep2 } from "localforage-removeitems"; +ep1(localforage); +ep2(localforage); export type LocalForage = typeof localforage; import { nanoid } from "nanoid"; @@ -307,12 +309,15 @@ export const clearFileHistoryOfEverythingByVault = async ( db: InternalDBs, vaultRandomID: string ) => { - const keys = await db.fileHistoryTbl.keys(); - for (const key of keys) { - if (key.startsWith(`${vaultRandomID}\t`)) { - await db.fileHistoryTbl.removeItem(key); - } - } + const keys = (await db.fileHistoryTbl.keys()).filter((x) => + x.startsWith(`${vaultRandomID}\t`) + ); + await db.fileHistoryTbl.removeItems(keys); + // for (const key of keys) { + // if (key.startsWith(`${vaultRandomID}\t`)) { + // await db.fileHistoryTbl.removeItem(key); + // } + // } }; /** @@ -339,12 +344,15 @@ export const clearAllSyncMetaMappingByVault = async ( db: InternalDBs, vaultRandomID: string ) => { - const keys = await db.syncMappingTbl.keys(); - for (const key of keys) { - if (key.startsWith(`${vaultRandomID}\t`)) { - await db.syncMappingTbl.removeItem(key); - } - } + const keys = (await db.syncMappingTbl.keys()).filter((x) => + x.startsWith(`${vaultRandomID}\t`) + ); + await db.syncMappingTbl.removeItems(keys); + // for (const key of keys) { + // if (key.startsWith(`${vaultRandomID}\t`)) { + // await db.syncMappingTbl.removeItem(key); + // } + // } }; export const insertSyncPlanRecordByVault = async ( @@ -422,11 +430,12 @@ export const clearExpiredSyncPlanRecords = async (db: InternalDBs) => { }); } - const ps = [] as Promise[]; - keysToRemove.forEach((element) => { - ps.push(db.syncPlansTbl.removeItem(element)); - }); - await Promise.all(ps); + // const ps = [] as Promise[]; + // keysToRemove.forEach((element) => { + // ps.push(db.syncPlansTbl.removeItem(element)); + // }); + // await Promise.all(ps); + await db.syncPlansTbl.removeItems(Array.from(keysToRemove)); }; export const getAllPrevSyncRecordsByVaultAndProfile = async ( @@ -475,12 +484,10 @@ export const clearAllPrevSyncRecordByVault = async ( db: InternalDBs, vaultRandomID: string ) => { - const keys = await db.prevSyncRecordsTbl.keys(); - for (const key of keys) { - if (key.startsWith(`${vaultRandomID}\t`)) { - await db.prevSyncRecordsTbl.removeItem(key); - } - } + const keys = (await db.prevSyncRecordsTbl.keys()).filter((x) => + x.startsWith(`${vaultRandomID}\t`) + ); + await db.prevSyncRecordsTbl.removeItems(keys); }; export const clearAllLoggerOutputRecords = async (db: InternalDBs) => {