# עזרה במחיקת תמונות מהשרת שהיו מצורפות לפוסטים שנמחקו

**URL:** https://meta.discourse.org/t/help-deleting-photos-from-server-that-were-attached-to-deleted-posts/294066
**Category:** Support
**Created:** [3 בפברואר,‏ 2024,‏ 8:54pm UTC](https://meta.discourse.org/t/help-deleting-photos-from-server-that-were-attached-to-deleted-posts/294066 "2024-02-03T20:54:31Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [3 בפברואר,‏ 2024,‏ 11:46pm UTC](https://meta.discourse.org/t/help-deleting-photos-from-server-that-were-attached-to-deleted-posts/294066/3 "2024-02-03T23:46:42Z")

</div>

I don’t think the `post_uploads` table exists any more. It’s now `uploads` and `upload_references`. You may need to update that old snippet to take that into account if you’re trying that method.

How have you deleted those posts? Just soft-deleting in the UI? I think the setting that cleans up orphaned images (`clean orphan uploads grace period hours`) doesn’t take into account whether they’re soft-deleted, and only cares if the image is still in the latest version of the post:

> [@How to make an image orphaned so that it gets removed?](https://meta.discourse.org/t/how-to-make-an-image-orphaned-so-that-it-gets-removed/79231/3):
>
> All the details are available in this job
> 
> [https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/clean\_up\_uploads.rb](https://github.com/discourse/discourse/blob/master/app/jobs/scheduled/clean_up_uploads.rb)
> 
> TL;DR: an image is orphaned if and only if it’s not referenced
> 
> - in the latest version of a post
> - in a draft
> - in a queued post
> - in a logo site setting
> - in a custom emoji
> - in a theme
> - in a user avatar/background/card image
> - in a category logo/background image

I think you can select all the posts in the rails console and use the PostDestroyer on them to hard delete them, and then the uploads will get cleaned up the next time `Jobs::CleanUpUploads` runs (or is manually triggered).

If it’s a whole category, for instance, I think you can use something like this:

```plaintext
category = Category.where(id: CATEGORY_ID).pluck(:id)  
topic = Topic.where(category_id: category).pluck(:id)

topic.each do |t|
  Post.where(topic_id: t).find_each do |p|
    PostDestroyer.new(Discourse.system_user, p).destroy
    p.destroy! 
  end
end

```

I think there’s also some conversation in this topic too that you may find useful [Delete deleted-posts permanently in bulk? - #57 by Simon\_Manning](https://meta.discourse.org/t/delete-deleted-posts-permanently-in-bulk/203289/57)

> ⚠ And I’ll add the usual warning about taking a backup before making changes in the rails console, just in case. Sharp Knife alert. 🚨

(Just an FYI, but `Jobs::DirectoryRefreshDaily` and `Jobs::DirectoryRefreshOlder` are the ones that populate the [User Directory](https://meta.discourse.org/u), so aren’t relevant here)

---

_[View the full topic](https://meta.discourse.org/t/help-deleting-photos-from-server-that-were-attached-to-deleted-posts/294066)._
