Skip to content

Commit e121fc1

Browse files
committed
refactor: delete chat in a transaction
1 parent 5399cbf commit e121fc1

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/chat.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -765,27 +765,19 @@ impl ChatId {
765765
);
766766

767767
let chat = Chat::load_from_db(context, self).await?;
768-
context
769-
.sql
770-
.execute(
771-
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?);",
772-
(self,),
773-
)
774-
.await?;
775-
776-
context
777-
.sql
778-
.execute("DELETE FROM msgs WHERE chat_id=?;", (self,))
779-
.await?;
780768

781769
context
782770
.sql
783-
.execute("DELETE FROM chats_contacts WHERE chat_id=?;", (self,))
784-
.await?;
785-
786-
context
787-
.sql
788-
.execute("DELETE FROM chats WHERE id=?;", (self,))
771+
.transaction(|transaction| {
772+
transaction.execute(
773+
"DELETE FROM msgs_mdns WHERE msg_id IN (SELECT id FROM msgs WHERE chat_id=?)",
774+
(self,),
775+
)?;
776+
transaction.execute("DELETE FROM msgs WHERE chat_id=?", (self,))?;
777+
transaction.execute("DELETE FROM chats_contacts WHERE chat_id=?", (self,))?;
778+
transaction.execute("DELETE FROM chats WHERE id=?", (self,))?;
779+
Ok(())
780+
})
789781
.await?;
790782

791783
context.emit_msgs_changed_without_ids();

0 commit comments

Comments
 (0)