[plasma-mobile/raven] src/ravend/src: Delete folder with transaction

Devin Lin <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 30a411c9d4354a501af7225c114d94c2e5c205d2 by Devin Lin, on behalf of Alexander Malygin.
Committed on 20/07/2026 at 17:56.
Pushed by devinlin into branch 'master'.

Delete folder with transaction

M  +11   -6    src/ravend/src/db/operations.rs
M  +2    -2    src/ravend/src/imap/worker.rs

https://invent.kde.org/plasma-mobile/raven/-/commit/30a411c9d4354a501af7225c114d94c2e5c205d2

diff --git a/src/ravend/src/db/operations.rs b/src/ravend/src/db/operations.rs
index 37058ba..d11fdce 100644
--- a/src/ravend/src/db/operations.rs
+++ b/src/ravend/src/db/operations.rs
@@ -196,13 +196,18 @@ pub fn delete_message_by_uid(conn: &Connection, account_id: &str, folder_id: &st
     Ok(false)
 }
 
-pub fn delete_folder_by_uid(conn: &Connection, folder_id: &str) -> Result<bool> {
-    
-    conn.execute("DELETE FROM folder WHERE id = ?1", [&folder_id])?;
-    conn.execute("DELETE FROM thread_folder WHERE folderId = ?1", [&folder_id])?;
-    conn.execute("DELETE FROM message WHERE folderId = ?1", [&folder_id])?;
-    return Ok(true);
+pub fn delete_folder_by_uid(conn: &mut Connection, folder_id: &str) -> Result<bool> {
+    let tx = conn.transaction()?;
+
+    tx.execute("DELETE FROM message_body WHERE id IN (SELECT id FROM message WHERE folderId = ?1)", [&folder_id])?;
+    tx.execute("DELETE FROM file WHERE messageId IN (SELECT id FROM message WHERE folderId = ?1)", [&folder_id])?;
+    tx.execute("DELETE FROM message WHERE folderId = ?1", [&folder_id])?;
+    tx.execute("DELETE FROM thread_folder WHERE folderId = ?1", [&folder_id])?;
+    let deleted = tx.execute("DELETE FROM folder WHERE id = ?1", [&folder_id])?;
+
+    tx.commit()?;
 
+    Ok(deleted > 0)
 }
 
 pub fn get_folder_message_uids(conn: &Connection, account_id: &str, folder_id: &str) -> Result<Vec<u32>> {
diff --git a/src/ravend/src/imap/worker.rs b/src/ravend/src/imap/worker.rs
index 8f7aa16..cffcd84 100644
--- a/src/ravend/src/imap/worker.rs
+++ b/src/ravend/src/imap/worker.rs
@@ -345,7 +345,7 @@ impl ImapWorker {
     fn sync_folders(&self, session: &mut ImapSession) -> Result<Vec<Folder>> {
         let mailboxes = session.list(Some(""), Some("*"))?;
 
-        let db = self.db.lock()
+        let mut db = self.db.lock()
             .map_err(|e| anyhow::anyhow!("Failed to acquire database lock: {}", e))?;
         let mut folders = Vec::new();
 
@@ -366,7 +366,7 @@ impl ImapWorker {
 
         for existing_folder_id in folders_ids.iter() {
             if !folders.iter().any(|i| &i.id == existing_folder_id) {
-                if !db::delete_folder_by_uid(db.conn(), existing_folder_id)? {
+                if !db::delete_folder_by_uid(db.conn_mut(), existing_folder_id)? {
                     error!("Failed to delete folder: {}", existing_folder_id);
                 }
                 else {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.