Thumbnails too large #138
Labels
No labels
bug
devops
duplicate
enhancement
good first issue
layout
next major release
next minor release
question
research
testing
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: lvl0/fedi-feed-router#138
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The slow way of loading the article thumbnails on Lemmy has me suspecting it's using the big images as thumbnails. Verify whether this is correct. If so, we should come up with a way to have a smaller image as thumbnail.
Confirmed, fixed, and verified against a live publish.
The suspicion was correct
Full-size images were being published as thumbnails. Measured from a real stored
image_url:All 49 Belga URLs end in the
:fullCDN selector. The chain was: parsers extractog:image→ stored asarticles.image_url→ passed ascustom_thumbnailto Lemmy, with no resizing anywhere.Why URL rewriting could not fix it
Belga's
picturepackcdnserves only full size. Probing:thumbnail,:large,:medium,:smalland:previewall returned HTTP 200 with zero bytes — the selectors are valid grammar but no alternate rendition exists. VRT (images.vrt.be) does honour?width=600(90 KB → 46 KB; note?w=is silently ignored), but that would have fixed only 23 of 72 articles.Dropping
custom_thumbnailand letting Lemmy generate its own was considered and rejected: Lemmy then fetches the article'sog:imageitself, which is the same oversized file. The slowness moves rather than disappears.The fix
Download the original, resize with GD to max 600px wide, upload to the instance's own pict-rs, and use the returned instance-hosted URL.
Three commits:
6ea3f92—LemmyRequest::postMultipart(); pict-rs sits outside the/api/v3prefix the existing methods hardcode34b78e6—ThumbnailUploaderplus wiring and failure logginge16368a— hoist the upload out of the stale-token retryThat third commit fixes a regression the finish-phase full-diff review caught and the per-commit reviews structurally could not: the thumbnail work had been added inside
createPost(), whichpublishToChannel()retries on a stale token. SincegetToken()returns a cached token, that retry is the ordinary post-expiry path — so a retry meant a second full download, resize, upload, and a duplicate warning log. The upload now happens once per publish and the resolved URL is passed into both attempts.Verified on a live publish
Lemmy post 2069227 on belgae.social:
Instance-hosted, not the source CDN. This also settles the one assumption the test suite could not: the pict-rs contract (multipart field
images[], response pathfiles.0.file) came from Lemmy 0.19's documentation rather than an observed upload, and the faked tests would have passed even if it were wrong. It is correct.Safety
Every failure path returns
nulland publishing continues without a thumbnail — download failure, non-image body, oversize, GD failure, upload failure, malformed response.LemmyPublisherlogs a warning whenever a thumbnail existed but no hosted URL came back, so a future break in the upload path surfaces rather than silently dropping thumbnails.Memory guards matter here: the worker runs at
memory_limit=128Mand a 4000×2256 JPEG decodes to ~27 MB in GD, soMAX_SOURCE_BYTES(10 MB) andMAX_SOURCE_PIXELS(50M) are both checked beforeimagecreatefromstring(). GD is available; no new dependency.Not covered
The live verification used a VRT article. The Belga path runs the same code at a much larger decode, and while the pixel guard is unit-tested, no real Belga publish has been observed. Worth watching the first one.
Verification: 1188 tests / 2891 assertions green, Pint clean (340 files), PHPStan clean.
pr-reviewerrun over the combined diff; its one must-fix ise16368a.