Inconsistent image persistence in Post Revisions: Why do some deleted images break while others persist indefinitely?

AI-generated summary

The discussion addresses a question posed by xlg256 regarding inconsistent image persistence in Post Revisions on a self-hosted Discourse instance. The user notes that while uploads are stored in Cloudflare R2, images deleted or replaced in posts behave differently when viewed in revision history. In most cases, historical images remain accessible, but in other instances, the underlying physical files are missing, leaving only placeholders.

xlg256 seeks clarification on how Discourse’s CleanUpUploads and orphan removal background jobs determine which uploads to retain versus purge. Specifically, the user asks why some images associated with older revisions persist indefinitely while others are thoroughly removed, and requests insights into the codebase logic related to upload_references and OptimizedImage. No responses to this inquiry were present in the provided text.

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:

  1. For most revisions where an image was replaced or deleted months ago, the image link in the revision remains fully accessible and loads correctly.

  2. 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 CleanUpUploads and 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