feat: atomic wrapup, movie, integration writes

Ride writes: WrapUpRequested/Completed (wrapup create/set_complete),
MovieDiscovered (resolve upsert, new+ext id only), PosterSynced (poster
handler upsert), MovieDeleted (delete_movie), WatchEventIngested (save).
Deps drop event_publisher: wrapup, ingest, delete_review, watchlist add,
review logger.

Remaining .publish( sites:
announce-only: users/delete_account UserDeleted, person/get +
get_credits PersonEnrichmentRequested, jobs/enrichment_staleness,
http-axum search, movies/sync_poster + poster_sync_handler +
image-converter backfill + users/update_profile ImageStored (object
storage), activitypub federation_event_bridge (reacting to events).
rides write, deferred: social/execute (see report),
activitypub review_handler MovieEnrichmentRequested (after
save_remote_review).
This commit is contained in:
2026-10-26 01:02:34 +01:00
parent 2f133afb96
commit 6c295866a0
51 changed files with 1281 additions and 329 deletions

View File

@@ -2,6 +2,7 @@ use async_trait::async_trait;
use crate::{
errors::DomainError,
events::DomainEvent,
models::{
Movie, MovieFilter, MovieProfile, MovieSummary, PersistedWatchEvent, WatchEvent,
collections::{PageParams, Paginated},
@@ -17,7 +18,7 @@ impl MovieCommand for InMemoryStore {
/// `movies.external_metadata_id` is UNIQUE: another movie row holding the
/// same external id is a constraint violation, which the sqlite adapter
/// surfaces as an infrastructure error.
async fn upsert_movie(&self, movie: &Movie) -> Result<(), DomainError> {
async fn upsert_movie(&self, movie: &Movie, events: &[DomainEvent]) -> Result<(), DomainError> {
let mut movies = self.movies.write().unwrap();
if let Some(external) = movie.external_metadata_id() {
let taken = movies.values().any(|m| {
@@ -31,13 +32,19 @@ impl MovieCommand for InMemoryStore {
}
}
movies.insert(movie.id().value(), movie.clone());
drop(movies);
self.record_events(events);
Ok(())
}
/// Schema: `reviews.movie_id REFERENCES movies(id)` has no cascade, so a
/// movie with reviews cannot be deleted. `watchlist_entries` and the
/// `movie_*` profile tables cascade; `watch_events.movie_id` is set to NULL.
async fn delete_movie(&self, movie_id: &MovieId) -> Result<(), DomainError> {
async fn delete_movie(
&self,
movie_id: &MovieId,
events: &[DomainEvent],
) -> Result<(), DomainError> {
let id = movie_id.value();
if !self.movies.read().unwrap().contains_key(&id) {
return Ok(());
@@ -59,12 +66,14 @@ impl MovieCommand for InMemoryStore {
.unwrap()
.retain(|(_, movie), _| *movie != id);
self.movie_profiles.write().unwrap().remove(&id);
let mut events = self.watch_events.write().unwrap();
for event in events.iter_mut() {
let mut events_guard = self.watch_events.write().unwrap();
for event in events_guard.iter_mut() {
if event.movie_id().map(|m| m.value()) == Some(id) {
*event = detached_from_movie(event);
}
}
drop(events_guard);
self.record_events(events);
Ok(())
}
}