mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-21 23:05:46 +00:00
c4a283b809
The previous design handed every <img> its own URL.createObjectURL for the same cached Blob. WebKitGTK shrugged it off, but Chromium/WebView2 keys its decoded-image cache by URL — so identical thumbnails were re-decoded once per instance. On Windows this made cover/artist grids painfully slow even when blobs were warm in memory. Refactor the URL layer to be refcounted and shared: - New acquireUrl(cacheKey) / releaseUrl(cacheKey) API. First acquire creates the URL; subsequent acquires return the same string and bump the refcount. Revoke is deferred 500 ms after the count hits zero so in-flight decodes finish cleanly. - useCachedUrl uses a lazy useState initializer: when the blob is hot, the very first <img src> is already the blob URL. No fetchUrl→blobUrl swap, no decode thrash, no race against the LRU. - CachedImage passes fallbackToFetch=false: previously the <img> briefly carried the raw server URL while the blob resolved, which triggered an HTTP fetch that the browser then aborted when src flipped to blob: — visible in DevTools as a flood of "Pending / 0 B" requests. Memory hits remain instant via the synchronous acquire path; cold paths now do a single fetch via getCachedBlob. - invalidateCacheKey / clearImageCache now also purge URL entries. Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>