watchlist add: event only if inserted; adr 0015 jetstream/relay accuracy; drop vacuous assert

This commit is contained in:
2026-10-26 01:56:38 +01:00
parent d0568d7933
commit bde8040cc3
7 changed files with 58 additions and 14 deletions

View File

@@ -16,15 +16,23 @@ use super::InMemoryStore;
#[async_trait]
impl WatchlistRepository for InMemoryStore {
/// `INSERT OR IGNORE` on UNIQUE(user_id, movie_id): adding twice is a no-op.
/// `INSERT OR IGNORE` on UNIQUE(user_id, movie_id): adding twice is a no-op
/// and, like the adapter, records events only for the row it inserted.
async fn add(&self, entry: &WatchlistEntry, events: &[DomainEvent]) -> Result<(), DomainError> {
let key = (entry.user_id.value(), entry.movie_id.value());
self.watchlist
.write()
.unwrap()
.entry(key)
.or_insert_with(|| entry.clone());
self.record_events(events);
let inserted = {
let mut entries = self.watchlist.write().unwrap();
match entries.entry(key) {
std::collections::hash_map::Entry::Vacant(slot) => {
slot.insert(entry.clone());
true
}
std::collections::hash_map::Entry::Occupied(_) => false,
}
};
if inserted {
self.record_events(events);
}
Ok(())
}