mirror of
https://github.com/chatmail/core.git
synced 2026-05-16 13:26:38 +03:00
refactor: use SQL transaction in MsgId.delete_from_db()
This commit is contained in:
@@ -114,23 +114,15 @@ WHERE id=?;
|
|||||||
|
|
||||||
/// Deletes a message, corresponding MDNs and unsent SMTP messages from the database.
|
/// Deletes a message, corresponding MDNs and unsent SMTP messages from the database.
|
||||||
pub(crate) async fn delete_from_db(self, context: &Context) -> Result<()> {
|
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
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute("DELETE FROM smtp WHERE msg_id=?", (self,))
|
.transaction(move |transaction| {
|
||||||
.await?;
|
transaction.execute("DELETE FROM smtp WHERE msg_id=?", (self,))?;
|
||||||
context
|
transaction.execute("DELETE FROM msgs_mdns WHERE msg_id=?", (self,))?;
|
||||||
.sql
|
transaction.execute("DELETE FROM msgs_status_updates WHERE msg_id=?", (self,))?;
|
||||||
.execute("DELETE FROM msgs_mdns WHERE msg_id=?;", (self,))
|
transaction.execute("DELETE FROM msgs WHERE id=?", (self,))?;
|
||||||
.await?;
|
Ok(())
|
||||||
context
|
})
|
||||||
.sql
|
|
||||||
.execute("DELETE FROM msgs_status_updates WHERE msg_id=?;", (self,))
|
|
||||||
.await?;
|
|
||||||
context
|
|
||||||
.sql
|
|
||||||
.execute("DELETE FROM msgs WHERE id=?;", (self,))
|
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user