# Auto purge uploads from old deleted posts

**URL:** https://meta.discourse.org/t/auto-purge-uploads-from-old-deleted-posts/51306
**Category:** Feature
**Created:** [October 9, 2016, 5:35pm UTC](https://meta.discourse.org/t/auto-purge-uploads-from-old-deleted-posts/51306 "2016-10-09T17:35:57Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![markersocial](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/markersocial/32/170136_2.png) [@markersocial](https://meta.discourse.org/u/markersocial)
#### Post date: [February 23, 2026, 2:58pm UTC](https://meta.discourse.org/t/auto-purge-uploads-from-old-deleted-posts/51306/7 "2026-02-23T14:58:34Z")

</div>

That is great! Really nice solution. 🙂

I wonder if using the same strategy of stripping markdown upload references in posts could make sense for the reverse scenario, when an upload is destroyed but posts referencing it remain live.

If I destroy an upload like:

```ruby
Upload.find(123).destroy

```

If upload 123 was used by any users for:

- profile custom avatar
- profile background
- card background

All the references are wiped, seemingly from:

before\_destroy (wipe background/card banner upload references)

[https://github.com/discourse/discourse/blob/6759ad71cac395697b2978eb34fcfbf1162d30d1/app/models/upload.rb#L53](https://github.com/discourse/discourse/blob/6759ad71cac395697b2978eb34fcfbf1162d30d1/app/models/upload.rb#L53)

after\_destroy (wipe avatar upload references)

[https://github.com/discourse/discourse/blob/6759ad71cac395697b2978eb34fcfbf1162d30d1/app/models/upload.rb#L60](https://github.com/discourse/discourse/blob/6759ad71cac395697b2978eb34fcfbf1162d30d1/app/models/upload.rb#L60)

If the post ids associated with an upload id could be used to queue stripping the upload markdown when destroyed, I think that could potentially prevent dead upload references in non-deleted posts when an upload is manually destroyed.

Ideally preserving upload markdown for any upload ids that were not destroyed, if say, one post has two uploads but only one was destroyed.

E.g. If deleting an upload referenced in more than one post (such as quote posts) via [https://meta.discourse.org/t/legal-compliance-plugin/356331](https://meta.discourse.org/t/legal-compliance-plugin/356331) or the rails CLI.

---

_[View the full topic](https://meta.discourse.org/t/auto-purge-uploads-from-old-deleted-posts/51306)._
