Any api to purge old deleted posts / uploads

AI-generated summary

In a Support thread titled “Any api to purge old deleted posts / uploads,” adopilot reports running out of server space despite bulk-deleting old posts with uploads — uploads remain and aren’t purged automatically. They ask if there’s a way to mark uploads as orphans for Sidekiq cleanup or fully purge deleted topics. codinghorror tags zogstrip, who suggests running a direct SQL command to delete orphaned post_uploads linked to deleted posts. adopilot clarifies they deleted via the advanced search UI, and shares a custom SQL script to delete uploads tied to deleted topics, even if individual posts weren’t marked deleted — noting Discourse’s behavior of leaving posts undeleted after topic deletion is inconsistent. They also list Sidekiq jobs to trigger manually (CleanUpUploads, PurgeDeletedUploads, etc.) and run ./launcher cleanup to reclaim space. Later, nathank seeks to combine both SQL approaches into a single console script, asking about the rails db password — which they later answer themselves: use the DISCOURSE_DB_PASSWORD from app.yml. nathank notes the underlying issue (posts not deleted with topics) has since been fixed in newer Discourse versions, making the combined script mostly obsolete except for legacy data.

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 have topics.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

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)

We did delete post from advanced search result page


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.

Pedido de Ajuda!

Alguém esperto pode me orientar sobre como combinar:

E

para criar um excelente limpador de uploads ĂłrfĂŁos que rode pelo console?

Notei que, ao usar rails db, sou solicitado a informar a Senha do usuário discourse:. O que devo fazer com isso?

Para responder Ă s minhas prĂłprias perguntas:

Na verdade, isso agora está obsoleto. Pelo menos para posts, já que o problema de não excluir posts de um tópico excluído foi resolvido há algum tempo.

Posts mais antigos ainda precisarão de alguma solução criativa.

Use a variável DISCOURSE_DB_PASSWORD que está no app.yml.