Any api to purge old deleted posts / uploads

Our discource is runing out of space on server.
We did bulk deleted old posts whit uploads.
But We did not gain any space.
When I query table topics they only havetopics.deleted_by_id is not null
Uploads for these topics are still on server.

Is there any way to make this Uploads orphans so sidekiq can clean these?
Or is there any way to PRUGE deleted topics so they do not consume space any more ?

I saw auto purge uploads from old deleted posts , but one year has past since post maded whit no replays.
So I started searching my way to release space on server

1 Like

Any thoughts @zogstrip?

Not sure how you bulk deleted the old posts/topics but this should fix it

# ssh into server
cd /var/discourse
./launcher enter app
rails db
DELETE FROM post_uploads WHERE post_id IN (SELECT id FROM posts WHERE deleted_at IS NOT NULL)
5 Likes

We did delete post from advanced search result page


1 Like

Here is my tsql for deleting uploads

Warning

This tsql delete uploads from post whic is not deletete but belong to topics whic is deleted.
I do no why discource left undeleted posts when topic is deleted.
But from my poin of view.
If topic is deleted, then all posts shoud be deleted in topics. Not just first one.
This script delete uploads for all posts which belong to deleted topic no matter if post is deleted or not.

delete from public.post_uploads
where id in (
SELECT 
	post_uploads.id
--    ,uploads.filesize
 --   ,posts.id
    --,topics.id
FROM 
  public.topics
  inner join public.posts on topics.id=posts.topic_id
  inner join public.post_uploads on posts.id=post_uploads.post_id
  inner join public.uploads on post_uploads.upload_id=uploads.id
WHERE 
	topics.deleted_by_id is not null
  )

I am not for sure which of sidekiq jobs need to be triggered , but I get released space after manual triggering next Workers in scheduler

  • Jobs::CleanUpUploads
  • Jobs::PurgeDeletedUploads
  • Jobs::DirectoryRefreshDaily
  • Jobs::DirectoryRefreshOlder

And called sudo ./launcher cleanup over SSH.

2 Likes

Call for Help!

Can a clever person walk me through combining:

AND

to make an awesome orphaned uploads purger run from the console?

I note that when I use rails db, I’m asked for Password for user discourse:. What do I do with that?

To answer my own questions:

Actually, this is now obsolete. At least for posts since the issue of not deleting posts of a deleted topic was fixed some time back.

Posts older than that will still need some sort of cute solution.

Use the DISCOURSE_DB_PASSWORD which is in app.yml

1 Like