Hi Discourse team and community,
I’ve noticed an interesting behavior regarding image handling within Post Revisions on my self-hosted Discourse instance, and I’d like to understand the underlying mechanism.
Context:
-
My site has image uploads routed to Cloudflare R2 (S3-compatible storage).
-
Over the past few months, I have performed several edits on posts that involved replacing or removing old images with new ones.
-
All original image uploads reside in R2.
The Observation: When I check the Post Revisions history for these older posts:
-
For most revisions where an image was replaced or deleted months ago, the image link in the revision remains fully accessible and loads correctly.
-
For a few specific revisions, the image is completely broken or missing its underlying physical file, leaving just a placeholder.
My Question:
-
How does Discourse’s
CleanUpUploadsand orphan removal background job differentiate between these revisions? -
Why do some historical revision images persist indefinitely in R2 (or cache) even after being removed from the latest post body, while others are thoroughly purged or lose their optimized variants?
Any insights into the codebase or database logic (upload_references / OptimizedImage) regarding revisions would be greatly appreciated!
Leo