From 8eee389c098d82098f04f3e1a6154126e15d4f0b Mon Sep 17 00:00:00 2001 From: link2xt Date: Sun, 23 Jul 2023 11:59:03 +0000 Subject: [PATCH] refactor: use SQL transaction in MsgId.delete_from_db() --- src/message.rs | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/src/message.rs b/src/message.rs index d72344465..594fab07e 100644 --- a/src/message.rs +++ b/src/message.rs @@ -114,23 +114,15 @@ WHERE id=?; /// Deletes a message, corresponding MDNs and unsent SMTP messages from the database. pub(crate) async fn delete_from_db(self, context: &Context) -> Result<()> { - // We don't use transactions yet, so remove MDNs first to make - // sure they are not left while the message is deleted. context .sql - .execute("DELETE FROM smtp WHERE msg_id=?", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs_mdns WHERE msg_id=?;", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs_status_updates WHERE msg_id=?;", (self,)) - .await?; - context - .sql - .execute("DELETE FROM msgs WHERE id=?;", (self,)) + .transaction(move |transaction| { + transaction.execute("DELETE FROM smtp WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs_mdns WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs_status_updates WHERE msg_id=?", (self,))?; + transaction.execute("DELETE FROM msgs WHERE id=?", (self,))?; + Ok(()) + }) .await?; Ok(()) }