feat: add IndexedDB cache migrations and quota recovery - #225
truthixify merged 6 commits into
Conversation
|
@whitezaddy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
The migration test never changes the database version, and CACHE_VERSION remains 1, so it only reopens the same schema. Please add a real version step and prove records and the last-seen cursor survive a v1 to v2 upgrade. |
Working on it |
Kindly review again |
|
The migration and quota tests now cover the requested paths. One blocker remains: CacheQuotaError is only exported from cache.ts, while the Stellar public barrel exports IndexedDBCache without the error. Please export CacheQuotaError from src/chains/stellar/index.ts so callers can handle the typed failure. |
I have updated src/chains/stellar/index.ts to export CacheQuotaError so callers can now properly handle the typed error! |
|
Merged. The migration coverage and typed quota recovery now meet the issue requirements. Thanks for addressing the review carefully. |
Fix: Add IndexedDB cache migrations and quota recovery
Closes #207
Problem
Previously,
IndexedDBCachewould unconditionally delete both theannouncementsandmetastores whenever the schema version changed. This meant that a browser upgrade or schema bump could wipe out the entire scan cache, leading to data loss and degraded performance while forcing clients to rebuild from scratch. Additionally, it did not distinguishQuotaExceededErrorfrom other write errors, lacking the ability to dynamically adapt when the browser's storage limits were hit.Solution
This PR resolves these issues by introducing safe versioned migrations and bounded quota recovery for IndexedDB:
onupgradeneededhandler inIndexedDBCacheto checkoldVersionand only create stores/indices if they don't already exist. It no longer aggressively drops stores when version bumps occur.IndexedDBCache.putnow natively catchesQuotaExceededError. If the quota is exceeded, the cache falls back to aggressive bounded eviction (halving its capacity limits to make room) and retries the operation.CacheQuotaError, providing a typed error for callers to handle.announcementsstore. Themetastore remains untouched during eviction sweeps, ensuring that thelastSeencursor safely survives quota panics.Testing
Added comprehensive unit tests inside
cache.idb.test.ts:IDBObjectStoreto throwQuotaExceededErrorintentionally.lastSeen.QuotaExceededErrorthrows the explicitCacheQuotaError.