fix: close IndexedDB connections after each cache operation - #241
pranayr710 wants to merge 1 commit into
Conversation
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 AOSSIE-Org#216
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: AOSSIE-Org/OrgExplorer/.coderabbit.yaml Review profile: ASSERTIVE Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. WalkthroughThe cache functions now create IndexedDB requests or transactions before returning promises. Each function closes its database connection immediately. Existing TTL, success, and error handling remain unchanged. ChangesIndexedDB cache cleanup
Priority: ⬆️ High Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: High Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. A rabbit reads each line, Comment |
Fixes #216
Problem
openDB()opens a fresh IndexedDB connection on everycacheGet,cacheSetandcacheClearcall, and the returned handle is never closed. Analyzing an organization with several repositories fires hundreds of these cache calls (contributors, issues, pulls per repo), so hundreds ofIDBDatabaseconnections accumulate in the tab over a single session.Fix
Call
db.close()right after starting the transaction in each of the three functions. Per the IndexedDB spec,close()only takes effect once any in-flight transaction on that connection settles, so this is safe — it doesn't cut off the read/write in progress, it just stops the connection from lingering afterward.1 file changed, +10/−5.
Verification
jsdom(this repo's test environment) doesn't implement IndexedDB, so I verified with a throwaway Node script usingfake-indexeddb(not committed — installed with--no-savefor local verification only, then removed): instrumentindexedDB.opento count connections opened vs. explicitly closed, then run a representative sequence of 5 cache operations (cacheSet×2,cacheGet×2,cacheClear×1).The existing test suite (49 tests, 6 files) still passes unchanged.
Note
I found this issue unclaimed — no maintainer or reporter statement of intent to fix it — and built the patch directly given the volume of open issues here. Happy to adjust scope or close if a maintainer is already working this.
Summary by CodeRabbit