Resync linked media sidecars when a post is deleted #77

Closed
opened 2026-07-20 19:43:59 +00:00 by hugo · 1 comment
Owner

Source: Audit section 2.8.

Spec: specs/engine_side_effects.allium DeletePostSideEffects: "for media_link in post.linked_media: ensures MediaSidecarUpdated(media_link.media_id) — removes post from media sidecar's linkedPostIds". Media sidecars carry linkedPostIds (specs/frontmatter.allium MediaSidecar).

bDS2: ../bDS2/lib/bds/posts.ex delete_post collects linked media ids first and calls sync_deleted_post_media_sidecar/1 (→ Media.sync_media_sidecar) for each after deletion.

Current behaviour (RuDS): crates/bds-core/src/engine/post.rs delete_post (~line 474) deletes the post_media rows but never rewrites the affected media sidecars, so their linkedPostIds keep referencing the deleted post — a divergence metadata diff will surface, and rebuild-from-filesystem would resurrect dead links.

Task: In delete_post, capture media_ids from post_media (ordered per bDS2: sort_order, media_id) before deleting the rows, then after deletion rewrite each media's sidecar (engine/media.rs already has the sidecar writer — reuse whatever update_media uses). Check crates/bds-core/src/engine/post_media.rs link/unlink paths also keep sidecars in sync (spec: metadata must flush to filesystem).

Acceptance: Test: link media to post, publish (sidecar contains post id), delete post → sidecar no longer lists the post id.

**Source:** Audit section 2.8. **Spec:** `specs/engine_side_effects.allium` DeletePostSideEffects: "for media_link in post.linked_media: ensures MediaSidecarUpdated(media_link.media_id) — removes post from media sidecar's linkedPostIds". Media sidecars carry `linkedPostIds` (`specs/frontmatter.allium` MediaSidecar). **bDS2:** `../bDS2/lib/bds/posts.ex` `delete_post` collects linked media ids first and calls `sync_deleted_post_media_sidecar/1` (→ `Media.sync_media_sidecar`) for each after deletion. **Current behaviour (RuDS):** `crates/bds-core/src/engine/post.rs` `delete_post` (~line 474) deletes the post_media rows but never rewrites the affected media sidecars, so their `linkedPostIds` keep referencing the deleted post — a divergence metadata diff will surface, and rebuild-from-filesystem would resurrect dead links. **Task:** In `delete_post`, capture `media_id`s from post_media (ordered per bDS2: sort_order, media_id) before deleting the rows, then after deletion rewrite each media's sidecar (engine/media.rs already has the sidecar writer — reuse whatever `update_media` uses). Check `crates/bds-core/src/engine/post_media.rs` link/unlink paths also keep sidecars in sync (spec: metadata must flush to filesystem). **Acceptance:** Test: link media to post, publish (sidecar contains post id), delete post → sidecar no longer lists the post id.
hugo added the bug label 2026-07-20 19:43:59 +00:00
Author
Owner

Implemented in 1cdc86b. Post deletion now captures linked media in deterministic sort-order/media-id order before removing associations, deletes the post, and rewrites every surviving media sidecar through a shared canonical media-sidecar writer. Link, unlink, media metadata updates, and media-file replacement now use that same writer, while a concurrently missing media record is ignored in parity with bDS2. Added a regression test covering a published post linked to multiple media items and preservation of another post's linkedPostIds, and updated the README. Verified with Allium check/analyse, cargo fmt --check, cargo check --workspace, cargo machete --with-metadata, cargo build --workspace, focused link/unlink/deletion tests, and cargo test --workspace (all passed; one intentional model-download test ignored).

Implemented in 1cdc86b. Post deletion now captures linked media in deterministic sort-order/media-id order before removing associations, deletes the post, and rewrites every surviving media sidecar through a shared canonical media-sidecar writer. Link, unlink, media metadata updates, and media-file replacement now use that same writer, while a concurrently missing media record is ignored in parity with bDS2. Added a regression test covering a published post linked to multiple media items and preservation of another post's linkedPostIds, and updated the README. Verified with Allium check/analyse, cargo fmt --check, cargo check --workspace, cargo machete --with-metadata, cargo build --workspace, focused link/unlink/deletion tests, and cargo test --workspace (all passed; one intentional model-download test ignored).
hugo closed this issue 2026-07-21 20:39:14 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: hugo/RuDS#77