Repository navigation
Keep avatars and commit images on the phone for a day - #27
Merged
Merged
Conversation
NativePHP's image element streams a remote URL every time it scrolls into view, but draws a file on the device from memory. So when an answer from devnull arrives, the avatars, commit images and link preview images in it that aren't on the phone yet are downloaded on a background thread, and the views draw each one from its file until it's a day old. Downloads start where answers arrive, in Client::get() and after a background refresh, never while a screen is drawn, so an image that isn't down yet loads from its URL as before. DownloadImages only keeps responses that are images, writes each file whole before it can be drawn, and clears out anything past the cache's age. DEVNULL_IMAGE_CACHE_HOURS changes the day, and 0 turns it off, which phpunit.xml does so other tests don't dispatch downloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Images were fetched again every time they scrolled into view. On iOS, mobile-ui draws a remote URL with SwiftUI's
AsyncImage, which keeps nothing once the image leaves the screen, and the server lifetimes are short: GitHub avatars say 5 minutes, commit images an hour. So scrolling the Log meant spinners and repeat requests.This keeps them on the phone for a day, in the app rather than in mobile-ui.
How it works
ImageCache::src()gives an image element the downloaded file for a URL while it's under 24 hours old, and the URL otherwise. mobile-ui draws a device file through its own in-memory cache, with no network.Client::get()and after a background refresh,ImageCache::prefetch()finds the avatars, commit images and link preview images in it that aren't on the phone yet. It hands them toDownloadImages, anAsyncTaskon NativePHP's background thread.DownloadImagesfetches six at a time and only keeps responses that are images. It writes each file whole before renaming it into place, and clears out files past the cache's age, so the folder holds about a day's worth.DEVNULL_IMAGE_CACHE_HOURSsets the age (24 by default). 0 turns it off, whichphpunit.xmldoes so existing tests don't dispatch downloads.Worth checking
storage/app/image-cache.Testing
852 tests pass and Pint is clean. New tests cover:
Not yet tried on a phone.
🤖 Generated with Claude Code