Skip to content

Commit 1846094

Browse files
jsibbison-squareImplementor
andauthored
fix(db): limit event transactions to listener mention kinds (#7932)
## Summary - Keep non-listener-mention event writes on the plain insert path without opening a transaction. - Preserve the transaction around listener mention event insertion and outbox enqueue. ## Validation - `cargo fmt --all -- --check` (Hermit) - Tests not run. Follow-up to Baxen’s review of #7793, point 1. Signed-off-by: Implementor <691cca7a870db1dad6990d5938d1b4a2a2ca9647ca81290b536c17b06b2e473f@buzz.block.builderlab.xyz> Co-authored-by: Implementor <691cca7a870db1dad6990d5938d1b4a2a2ca9647ca81290b536c17b06b2e473f@buzz.block.builderlab.xyz>
1 parent c4c8600 commit 1846094

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎crates/buzz-db/src/store/event.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,15 +355,19 @@ pub async fn insert_event(
355355
event: &Event,
356356
channel_id: Option<Uuid>,
357357
) -> Result<(StoredEvent, bool)> {
358-
let connection = crate::observability::acquire_writer(
358+
let mut connection = crate::observability::acquire_writer(
359359
pool,
360360
crate::observability::WriterOperation::EventWrite,
361361
)
362362
.await?;
363-
let mut tx = Transaction::begin(connection, None).await?;
364-
let result = insert_event_in_transaction(&mut tx, community_id, event, channel_id).await?;
365-
tx.commit().await?;
366-
Ok(result)
363+
if crate::operator_listener::is_listener_mention_kind(u32::from(event.kind.as_u16())) {
364+
let mut tx = Transaction::begin(connection, None).await?;
365+
let result = insert_event_in_transaction(&mut tx, community_id, event, channel_id).await?;
366+
tx.commit().await?;
367+
Ok(result)
368+
} else {
369+
insert_event_on(&mut connection, community_id, event, channel_id).await
370+
}
367371
}
368372

369373
/// Insert a Nostr event in a caller-owned PostgreSQL transaction.

0 commit comments

Comments
 (0)