Help deleting photos from server that were attached to deleted posts

After deleting several thousand posts with photos the uploads in the admin section remains the same. This setting was set to 1. Is there a way to purge all the uploads associated with deleted posts faster?

purge deleted uploads grace period days

Grace period (in days) before a deleted upload is erased.

I did this what I saw in another post but after rebuilding nothing was gone

went into sidkiq

* Jobs::CleanUpUploads
* Jobs::PurgeDeletedUploads
* Jobs::DirectoryRefreshDaily
* Jobs::DirectoryRefreshOlder

I went from 13.7gb uploads to 14gb after deleting everything. Seems the more I delete the higher the uploads data goes.

Im not sure I understand this. I have not uploaded anything but deleted posts and categories on a test site. Theres no users right now and its been about 3 hours or so. from 13.7 to now showing this. Orphans uploads set to delete in an hour and hasnt happened.

Screenshot 2024-02-03 233347

I see this thread that discusses alot but nothing happened?

Then this one here.

and Ive tried everything in rails mentioned, sidekiq, and with commands in that thread and still nothing deletes. Over should be hundreds if not thousands of images deleted as the users posts removed posted photos with every thread.

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:

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:

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

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

(Just an FYI, but Jobs::DirectoryRefreshDaily and Jobs::DirectoryRefreshOlder are the ones that populate the User Directory, so aren’t relevant here)

5 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.