From b7872421f4bb2f021ec50ab7c4dd48aaa17a681c Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Tue, 16 Jan 2024 15:33:13 +0800 Subject: [PATCH] Use transaction in sync ingest (#1939) --- core/crates/sync/src/ingest.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/crates/sync/src/ingest.rs b/core/crates/sync/src/ingest.rs index 78d2dfbf3..c37ec4efc 100644 --- a/core/crates/sync/src/ingest.rs +++ b/core/crates/sync/src/ingest.rs @@ -142,13 +142,19 @@ impl Actor { } async fn apply_op(&mut self, op: CRDTOperation) -> prisma_client_rust::Result<()> { - // TODO: Needs to be transaction-ified - ModelSyncData::from_op(op.clone()) - .unwrap() - .exec(&self.db) - .await?; + self.db + ._transaction() + .run(|db| async move { + ModelSyncData::from_op(op.clone()) + .unwrap() + .exec(&db) + .await?; - write_crdt_op_to_db(&op, &self.db).await?; + write_crdt_op_to_db(&op, &db).await?; + + Ok(()) + }) + .await?; self.io.req_tx.send(Request::Ingested).await.ok();