Cache the web card database in IndexedDB, gated on latest.json - #105
Open
Manwe-777 wants to merge 1 commit into
Open
Cache the web card database in IndexedDB, gated on latest.json#105Manwe-777 wants to merge 1 commit into
Manwe-777 wants to merge 1 commit into
Conversation
The web build downloaded the ~5MB en-database.sqlite.gz from the Supabase mirror on every page load: latest.json was read only to check that the release publishes SQLite, never compared against anything, and the mirror answers Cache-Control: no-cache so the browser revalidates too. The Electron build has always version-checked against its disk cache; the web path lost that in the SQLite migration. fetchDatabaseWeb now mirrors ensureDatabaseFile against IndexedDB: the inflated database lives in the mtgatool-local KV store keyed by lang with the version it holds, each boot moves only the tiny latest.json, and the payload downloads solely when the published version is newer. An unreachable latest.json or a failed download serves the cached copy — a version behind is far better than no cards — a corrupt cache entry is ignored via the SQLite-header check, and a broken IndexedDB falls through to the network. The source label distinguishes cache:vN from mirror:vN. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughChangesWeb database cache
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: ⚪ Minimal · up to The change adds version-gated IndexedDB caching for the web card database with fallback behavior, and no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant loadWeb
participant fetchDatabaseWeb
participant IndexedDB
participant ReleaseMetadata
participant Mirror
loadWeb->>fetchDatabaseWeb: Request database
fetchDatabaseWeb->>IndexedDB: Read cached SQLite entry
fetchDatabaseWeb->>ReleaseMetadata: Read release metadata
fetchDatabaseWeb->>Mirror: Download and inflate payload
Mirror-->>fetchDatabaseWeb: Return validated SQLite bytes
fetchDatabaseWeb->>IndexedDB: Store bytes and release version
fetchDatabaseWeb-->>loadWeb: Return bytes and source
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
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.
What
The web build downloads the ~5MB
en-database.sqlite.gzfrom the Supabase mirror on every page load.latest.jsonis fetched, but only to check that the release publishes SQLite — it is never compared against anything, there is no local cache, and the mirror answersCache-Control: no-cacheso the browser's HTTP cache revalidates as well. The Electron build has always had the version-gated disk cache; the web path lost that behavior in the SQLite migration.This gives the web the same flow against IndexedDB:
mtgatool-localKV store undercardsDb:{lang}together with the version it holds.latest.json; the payload moves solely when the published version is newer than the cached one.latest.jsonor a failed download serves the cached copy (a version behind beats no cards); a corrupt cache entry is ignored via the SQLite-header check; a broken IndexedDB falls through to the network, never blocking the cards.cache:vNfrommirror:vN.Verified
npm run start:web: after the first (seeding) load, a reload's only request to the Supabase bucket islatest.json— no.gz— and the worker boots from the cached bytes.fetchDatabaseWeb.spec.tscovers the decision paths: up-to-date cache skips the payload entirely, offline falls back to the cache, no-cache-no-network yields null, corrupt cache is ignored.dbBytesto the worker is safe with the cache: the structured clone into IndexedDB happens atkvPutbefore the buffer is transferred/detached.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Bug Fixes