1.4 KiB
1.4 KiB
Plan: Persist Scryfall Metadata
Objective
Persist fetched Scryfall card metadata in the browser's IndexedDB. This ensures that:
- Metadata (including the newly added rich fields) is saved across sessions.
- Pack generation can rely on this data without re-fetching.
- The application works better offline or with poor connection after initial fetch.
Implementation Steps
-
Create
src/client/src/utils/db.ts- Implement a lightweight IndexedDB wrapper.
- Database Name:
mtg-draft-maker - Store Name:
cards - Methods:
putCard,getCard,getAllCards,bulkPut.
-
Update
ScryfallService.ts- Import the DB utilities.
- In
constructoror a newinitialize()method, load all persisted cards into memory (cacheByIdandcacheByName). - In
fetchCollection,fetchSetCards, etc., whenever cards are fetched from API, save them to DB viabulkPut. - Modify
fetchCollectionto check memory cache (which is now pre-filled from DB) before network.
-
Refactor
fetchCollectiondeduplication- Since cache is pre-filled, the existing check
if (this.cacheById.has(...))will effectively check the persisted data.
- Since cache is pre-filled, the existing check
Verification
- Reload page -> Check if cards are loaded immediately without network requests (network tab).
- Check Application -> Storage -> IndexedDB in browser devtools (mental check).