Skip to content

upload: report orphan images with find_usages and find_orphans - #196

Merged
chai-inu merged 1 commit into
mainfrom
upload/report
Aug 14, 2026
Merged

chai-inu merged 1 commit into
mainfrom
upload/report

Conversation

@chai-inu

Copy link
Copy Markdown
Member

Summary

Adds orphan detection for uploads: find_usages(sha) and find_orphans(), plus a make upload-report target.

What's in here

  • services/uploads.py:
    • find_usages(sha) — scans Article.body/body_draft, Answer.body/body_draft, Comment.body, Submission.description, and the archive tables for the sha. The URL embeds the sha, so a LIKE hit is exact. Works today.
    • find_orphans() — uploads whose sha appears in no body. Inert until the SQL PR lands (crud.upload is still stubbed, so there are no shas to scan); it comes alive when the table exists.
  • scripts/upload_report.py + make upload-report — list orphans (or usages of a single sha via --sha). Nothing deletes.

Why computed, not stored

delete_forever overwrites body, body_draft and every archive row with "[DELETED]", so references leave the database and a scan is always correct — no join table to maintain, no delete hook to forget.

Deferred

The find_usages/find_orphans test lives in the SQL PR (it needs the real Upload table). This PR is code-only and lint-clean.

Usage is computed by scanning bodies and archive tables rather than stored in a
join table, because delete_forever overwrites body, body_draft and every
archive row with [DELETED] -- references leave the database, so a scan is
always correct. find_orphans is inert until the Upload table lands (crud is
stubbed); find_usages works today. Add a make upload-report target.
@chai-inu
chai-inu merged commit 0c4e32a into main Aug 14, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant