feat: add IndexedDB cache migrations and quota recovery - #225
Open
whitezaddy wants to merge 2 commits into
Open
whitezaddy wants to merge 2 commits into
whitezaddy wants to merge 2 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! 🚀 |
Contributor
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.