From 36eb44642f7c18a3ba2694c451220ce800925542 Mon Sep 17 00:00:00 2001 From: pranayr710 <177966296+pranayr710@users.noreply.github.com> Date: Sat, 19 Sep 2026 22:42:04 +0530 Subject: [PATCH] fix: close IndexedDB connections after each cache operation openDB() opens a fresh IndexedDB connection on every cacheGet/cacheSet/ cacheClear call, and the returned handle was never closed. Analyzing an organization with several repos issues hundreds of these calls, so hundreds of IDBDatabase connections accumulate in the tab - each one counted in devtools, contributing to memory growth and able to block a future version upgrade of the database. IDBDatabase.close() defers until any in-flight transaction on that connection settles, so it's safe to call immediately after starting the transaction rather than waiting on its completion event. Fixes #216 --- src/services/github.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/services/github.js b/src/services/github.js index a4180fa..8ffe74c 100644 --- a/src/services/github.js +++ b/src/services/github.js @@ -15,8 +15,11 @@ function openDB() { export async function cacheGet(key) { try { const db = await openDB() + // close() only takes effect once the in-flight transaction below settles, + // so it's safe to call right away instead of leaving the connection open. + const req = db.transaction(STORE, 'readonly').objectStore(STORE).get(key) + db.close() return new Promise(res => { - const req = db.transaction(STORE, 'readonly').objectStore(STORE).get(key) req.onsuccess = () => { const r = req.result if (!r || Date.now() - r.ts > TTL_MS) return res(null) @@ -30,9 +33,10 @@ export async function cacheGet(key) { export async function cacheSet(key, value) { try { const db = await openDB() + const tx = db.transaction(STORE, 'readwrite') + tx.objectStore(STORE).put({ k: key, v: value, ts: Date.now() }) + db.close() return new Promise(res => { - const tx = db.transaction(STORE, 'readwrite') - tx.objectStore(STORE).put({ k: key, v: value, ts: Date.now() }) tx.oncomplete = () => res(true) tx.onerror = () => res(false) }) @@ -42,9 +46,10 @@ export async function cacheSet(key, value) { export async function cacheClear() { try { const db = await openDB() + const tx = db.transaction(STORE, 'readwrite') + tx.objectStore(STORE).clear() + db.close() return new Promise(res => { - const tx = db.transaction(STORE, 'readwrite') - tx.objectStore(STORE).clear() tx.oncomplete = () => res(true) tx.onerror = () => res(false) })