fix: evict stale cached images when Scryfall updates a scan#38
Open
spawnia wants to merge 4 commits into
Open
Conversation
Scryfall embeds a Unix timestamp in each image URI (e.g. `…png?1774978609`) that changes whenever the scan is updated. Previously, mtg-proxies cached images indefinitely and never re-downloaded them, so users would keep seeing outdated scans (e.g. early low-quality previews of newly spoiled cards) until they manually cleared the cache. get_image() now compares the cached file's mtime against the URI timestamp and deletes the file before downloading when it is stale.
The PDF printer caches cropped variants of card images alongside the base file (e.g. png_front_<uuid>_14_14.png). These are only generated when missing, so evicting just the base left the stale variants in place and the re-downloaded image was never used. Evict all matching stem_*.png variants together with the base file.
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.
Newly spoiled cards often appear on Scryfall with a low-quality preview scan first, replaced by a proper scan later. We noticed this when printing a deck that included a recently spoiled card — the printed proxy showed the blurry early scan despite Scryfall having the correct image available.
Scryfall's image URIs already carry a Unix timestamp (e.g.
…png?1774978609) that updates whenever the scan changes. The cache never checked it, so any image downloaded before the update would stay stale indefinitely.To validate the fix, we planted a different card's image as the cached file for the affected card, set its mtime to one second before the URI timestamp, and printed the deck twice — once with the unfixed code (wrong card appeared in the PDF) and once with this fix applied (correct card, freshly downloaded).
During that validation we also discovered that the PDF printer derives cropped variants from the base file (e.g.
png_front_<uuid>_14_14.png) and caches them alongside it, only regenerating them when missing. Evicting just the base left the stale variant in place, so the fix evicts those together with the base.