refactor: delete chat in a transaction

This commit is contained in:
link2xt
2024-11-20 14:19:41 +00:00
committed by l
parent 5399cbfffe
commit e121fc1389

View File

@@ -765,27 +765,19 @@ impl ChatId {
); );
let chat = Chat::load_from_db(context, self).await?; let chat = Chat::load_from_db(context, self).await?;
context
.sql
.execute(
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?);",
(self,),
)
.await?;
context context
.sql .sql
.execute("DELETE FROM msgs WHERE chat_id=?;", (self,)) .transaction(|transaction| {
.await?; transaction.execute(
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)",
context (self,),
.sql )?;
.execute("DELETE FROM chats_contacts WHERE chat_id=?;", (self,)) transaction.execute("DELETE FROM msgs WHERE chat_id=?", (self,))?;
.await?; transaction.execute("DELETE FROM chats_contacts WHERE chat_id=?", (self,))?;
transaction.execute("DELETE FROM chats WHERE id=?", (self,))?;
context Ok(())
.sql })
.execute("DELETE FROM chats WHERE id=?;", (self,))
.await?; .await?;
context.emit_msgs_changed_without_ids(); context.emit_msgs_changed_without_ids();