mirror of
https://github.com/chatmail/core.git
synced 2026-05-09 01:46:30 +03:00
refactor: delete chat in a transaction
This commit is contained in:
28
src/chat.rs
28
src/chat.rs
@@ -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();
|
||||||
|
|||||||
Reference in New Issue
Block a user