Uploads not getting orphaned and purged

Hello. I am facing the same or similar issue, can’t figure out why the files can’t get deleted. Anyone else having this issue still?
I ran some SQL queries and the “stuck” upload references seems to be all Drafts, but I checked my and other users Drafts and there are none. The Drafts tables are empty.
The orphan cleaning is enabled and settings are set to delete the orphans as fast as possible.
I attached a SQL query.

SELECT 
    uploads.original_filename,
    ROUND(uploads.filesize / 1000000.0, 2) AS size_in_mb,
    uploads.extension,
    uploads.created_at,
    uploads.url,
    upload_references.upload_id,
    upload_references.target_id,
    upload_references.target_type,
    upload_references.created_at,
    upload_references.updated_at
FROM upload_references
JOIN uploads ON uploads.id = upload_references.upload_id
ORDER BY uploads.filesize DESC
LIMIT 250

sql.csv (46,1 KB)

This happens since I installed the forum. Even when there was no custom themes or plugins installed.
Heck even the old forum logo I uploaded a few times (the first uploaded file ever) is still rerefenced as Draft and still in the uploads folder. :man_facepalming:
Theoretically I could filter all upload references and filter for Drafts by target_type, then delete from database… and let the sidekiq tasks handle the cleanup (am I right?)
but I’m using a self hosted instance and am quite new to Discourse, so better to ask here…
That would be a workaround, but still there is a question - why is this happening?

Hope someone has some suggestions, my disk space is growing exponentially :smile:

1 Like