Repository navigation
fix(collections): remove a personal collection's artwork when it is deleted - #2939
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 41 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Quick104
left a comment
There was a problem hiding this comment.
Review of 8b10824. The fix is right and its test fails on the base for the reported reason. One cleanup finding is inline. Two lower-severity notes that don't block this PR:
- Other delete paths and retries (low, follow-up). The sweep runs only on the HTTP delete. Profile delete and account cascades are already disclosed and tracked in #2910. The Audiobookshelf collection delete (
ABSCollectionStore.DeleteCollection) also removesuser_personal_collectionsrows of typemanual, and it doesn't sweep. Nothing retries a sweep that fails or never runs because the node died after the row delete: a repeated DELETE gets 404, so the uploaded poster stays. Collages are already covered, because theuser_personal_collection_poster_variants_queue_deletedtrigger hands them to the artwork revision collector on every delete path. A matchingAFTER DELETEtrigger onuser_personal_collectionsthat queuesOLD.poster_urlwould give the uploaded poster the same durable backstop on every path. That fits better in #2910 than here. The prefix sweep should stay either way, since it also reclaims displaced revisions the collector has no record of, and the SQLite user store. - Shared references (low). Collection imports store a client-supplied
poster_urlverbatim, so a crafted import can point collection B at a key under collection A's directory. Deleting A now removes the poster B names. Only a hand-built request can do this, and the damage is limited to the crafted collection's own poster. Real clients send template paths or URLs.
…eleted Deleting a personal collection removed its row but left its poster revisions and collages under user-collection-images/<id>/ for good. Sweep that prefix after the row delete commits, as admin collection deletion already does. A sweep failure only logs.
Admin and personal collection deletes now remove the collection's artwork directory through one helper. The admin path gains the detached, time-bounded context the personal path uses, so a client disconnect after the row delete no longer cancels its sweep. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8b10824 to
ae56677
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
Review summaryReviewed head: Addressed
Left for maintainers (not blocking)
Tests
Overlap with #2575
Validated features: none affected. No passed case on the v1.0 board touches collections. User manual: unaffected. This is storage housekeeping with no setting, label, or visible behavior. Apple/Android: no client change. Cross-provider review: two rounds with Codex (gpt-6.1-sol). The first raised the shared-reference note above. The second tested whether a collector trigger should replace the prefix sweep. It shouldn't: the sweep also reclaims displaced revisions the collector doesn't know about, and it covers the SQLite store. A trigger is a follow-up, not a replacement. Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)
🤖 Generated with Claude Code (claude-opus-5-5), cross-provider review by Codex (gpt-6.1-sol). |
|
Visible: deleting a personal collection can also remove artwork shown by another collection when its imported Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| } | ||
| ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), collectionImageCleanupTimeout) | ||
| defer cancel() | ||
| if _, err := store.DeletePrefix(ctx, fmt.Sprintf("%s/%s/", prefix, collectionID)); err != nil { |
There was a problem hiding this comment.
Orphaned artwork can persist without a durable retry because best-effort deletion runs after the collection row deletion commits, leaving a failure window for crashes or storage errors; immediate deletion also ignores issued-URL protection deadlines. Enqueue the removed artwork references and their protection deadlines in the same database transaction as the collection deletion, then let a retirement worker delete them when eligible.
Kody rule violation: Retire displaced media revisions transactionally and preserve URL deadlines
Prompt for LLM
File internal/api/handlers/collection_artwork.go:
Line 372:
Orphaned artwork can persist without a durable retry because best-effort deletion runs after the collection row deletion commits, leaving a failure window for crashes or storage errors; immediate deletion also ignores issued-URL protection deadlines. Enqueue the removed artwork references and their protection deadlines in the same database transaction as the collection deletion, then let a retirement worker delete them when eligible.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
Problem
Closes #2838
Related issue: #2910
Validation tasks: none affected
Deleting a personal collection removed its database row but left its uploaded poster and its generated collages in artwork storage, under
user-collection-images/<collection id>/. Nothing removed them later, so storage grew with every deleted collection that had artwork. This affects any deployment with artwork storage, filesystem or S3. Nothing visible breaks. Admin collections already clean up on delete.With this change,
DeletePersonalCollectionremoves the collection's artwork directory once the row delete has succeeded.Approach
After
deleteCollectionWithRevisionsucceeds, the handler callsremoveDeletedCollectionArtwork, which runsDeletePrefixonuser-collection-images/<id>/. Admin collection delete (cleanupDeletedCollection) now calls the same helper forcollection-images/<id>/, so it also gets the detached, time-bounded context described below. Before this change, a client disconnect right after an admin delete could cancel its sweep. The row is already gone at that point, so the cleanup runs on a context that a canceled request can't stop, bounded by the existing 30-second collection artwork cleanup timeout, the same patterncleanUpReplacedCollectionImageuses. A cleanup failure is logged and the delete still succeeds. A failed row delete or a revision mismatch leaves the artwork in place./api/v1and/api/v2both reach this method, so both are covered and neither contract changes. jellycompat doesn't delete personal collections. Clients are unaffected.Not covered here: deleting a profile (
PostgresUserStore.DeleteProfile) or an account (theusersforeign-key cascade) also removes that profile's or account's personal collections, in SQL. Neither path sweeps their artwork. Covering them needs the store to report which collection IDs it deleted, so it is tracked in #2910.Validation
go test ./internal/api/handlers/: pass.go build ./...,go vet ./internal/api/handlers/,gofmt -l: clean.make lint-changed: 0 issues.make verify-size-ratchetandmake verify-local-paths: pass.make test-gosuite and the web, contract and generated-artifact gates. The change touches no web,internal/apiv2, migration or route files.Evidence
No user-visible change. Results:
TestDeletePersonalCollectionRemovesArtwork, run againstmainatbe6527e50and this branch at8b108246b. The test seeds artwork for collectioncand another collectionc2, then deletesc.Risks
The cleanup deletes everything under one collection's prefix. Collection IDs are non-empty, and the trailing slash stops one ID from matching another (
cvsc2). A collage build that is still running when the collection is deleted could write a file after the cleanup; admin collection delete has the same window.Checklist
AI Disclosure
Note
Remove a personal collection's artwork blob directory when it is deleted
Adds a shared
removeDeletedCollectionArtworkhelper that sweeps the collection's artwork prefix from the blob store with a timeout context detached from request cancellation.CollectionHandler.DeletePersonalCollectioncalls it after the collection-row deletion succeeds; cleanup failures are logged and do not fail the deletion. Library collection cleanup now reuses the same helper.Macroscope summarized ae56677.