1.6 KiB
1.6 KiB
Plan: Server-Side Caching of Bulk Data
Objective
Implement server-side caching of both card images and metadata upon bulk parsing, ensuring the application relies on local assets rather than external Scryfall URLs.
Implementation Steps
-
Refactor Server Architecture (
CardService.ts)- Update storage paths to
public/cards/images(previouslypublic/cards) andpublic/cards/metadata. - Implement
cacheMetadatato save JSON files alongside images.
- Update storage paths to
-
Update API Endpoint (
index.ts)- Modify
POST /api/cards/cacheto handle metadata saving in addition to image downloading. - Update static file serving to map
/cardstopublic/cards, making images accessible at/cards/images/{id}.jpg.
- Modify
-
Update Client Logic (
CubeManager.tsx,PackGeneratorService.ts,LobbyManager.tsx)- Generation: Pass a flag (
useLocalImages) to the generator service. - Url Construction: Generator now produces URLs like
${origin}/cards/images/{id}.jpgwhen the flag is set. - Triggers:
CubeManagerimmediately sends parsed data to the server for caching before generating packs. - Consistency:
LobbyManagerupdated to look for images in the new/cards/imagespath for multiplayer sessions.
- Generation: Pass a flag (
Impact
- Performance: Initial "Parse Bulk" takes slightly longer (due to server cache call), but subsequent interactions are instant and local.
- Reliability: Application works offline or without Scryfall after initial parse.
- Precision: Metadata is now persisted as individual JSONs on the backend, ready for future complex backend algorithms.