From 1845807dc0ea4759ba574eec6f581d82c465f6b0 Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Tue, 12 Dec 2023 10:02:55 +0500 Subject: [PATCH] web: close idb connection on sqlite connection close --- apps/web/src/common/sqlite/sqlite.worker.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/web/src/common/sqlite/sqlite.worker.ts b/apps/web/src/common/sqlite/sqlite.worker.ts index 6a15dd39b..e7f904d26 100644 --- a/apps/web/src/common/sqlite/sqlite.worker.ts +++ b/apps/web/src/common/sqlite/sqlite.worker.ts @@ -34,6 +34,7 @@ type PreparedStatement = { let sqlite: SQLiteAPI; let db: number; +let vfs: IDBBatchAtomicVFS | AccessHandlePoolVFS | null = null; const preparedStatements: Map = new Map(); async function init(dbName: string, async: boolean, url?: string) { @@ -42,7 +43,7 @@ async function init(dbName: string, async: boolean, url?: string) { ? await SQLiteAsyncESMFactory(option) : await SQLiteSyncESMFactory(option); sqlite = Factory(SQLiteAsyncModule); - const vfs = async + vfs = async ? new IDBBatchAtomicVFS(dbName, { durability: "strict" }) : new AccessHandlePoolVFS(dbName); if ("isReady" in vfs) await vfs.isReady; @@ -126,6 +127,7 @@ async function close() { await sqlite.finalize(prepared.stmt); } await sqlite.close(db); + await vfs?.close(); } const worker = {