Any api to purge old deleted posts / uploads


(Admir Hodzic) #1

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


(Jeff Atwood) #2

Any thoughts @zogstrip?


(Régis Hanol) #3

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)

(Admir Hodzic) #4

We did delete post from advanced search result page



(Admir Hodzic) #5

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.