From f430b0efc79a169202f172c693ee1aa7de9fc19d Mon Sep 17 00:00:00 2001 From: Joscha Date: Sun, 7 Aug 2022 00:53:11 +0200 Subject: [PATCH] Fix db inconsistencies when deleting a room Since the euph_trees table can't have any foreign key constraints pointing to the euph_rooms table, deleting a room wouldn't delete that room's trees in euph_trees. Upon reconnecting to the room, those trees would then be displayed as placeholder messages without children. --- CHANGELOG.md | 1 + src/vault/euph.rs | 16 ++++++++++++++-- src/vault/prepare.rs | 1 - 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index db875d2..47abc39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Slowed down room history download speed ### Fixed +- Chat rendering when deleting and re-joining a room - Spacing in some popups ## v0.1.0 - 2022-08-06 diff --git a/src/vault/euph.rs b/src/vault/euph.rs index b56ddb9..26dc177 100644 --- a/src/vault/euph.rs +++ b/src/vault/euph.rs @@ -472,13 +472,25 @@ impl EuphRequest { } fn delete(conn: &mut Connection, room: String) -> rusqlite::Result<()> { - conn.execute( + let tx = conn.transaction()?; + + tx.execute( " DELETE FROM euph_rooms WHERE room = ? ", - [room], + [&room], )?; + + tx.execute( + " + DELETE FROM euph_trees + WHERE room = ? + ", + [&room], + )?; + + tx.commit()?; Ok(()) } diff --git a/src/vault/prepare.rs b/src/vault/prepare.rs index ab8cb9c..8f55fb0 100644 --- a/src/vault/prepare.rs +++ b/src/vault/prepare.rs @@ -4,7 +4,6 @@ pub fn prepare(conn: &mut Connection) -> rusqlite::Result<()> { println!("Opening vault"); // This temporary table has no foreign key constraint on euph_rooms since // cross-schema constraints like that are not supported by SQLite. - // TODO Remove entries from this table whenever a room is deleted conn.execute_batch( " CREATE TEMPORARY TABLE euph_trees (