From 441848d195d908cdc9b0d083319104dd99cdf6ea Mon Sep 17 00:00:00 2001 From: Mikayla Date: Thu, 7 Sep 2023 15:23:37 -0700 Subject: [PATCH] Improve channel deletion to be DAG aware --- crates/collab/src/db/queries/channels.rs | 28 ++++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/crates/collab/src/db/queries/channels.rs b/crates/collab/src/db/queries/channels.rs index 01f47b1940..0eb6c45fe6 100644 --- a/crates/collab/src/db/queries/channels.rs +++ b/crates/collab/src/db/queries/channels.rs @@ -150,6 +150,21 @@ impl Database { .exec(&*tx) .await?; + // Delete any other paths that incldue this channel + let sql = r#" + DELETE FROM channel_paths + WHERE + id_path LIKE '%' || $1 || '%' + "#; + let channel_paths_stmt = Statement::from_sql_and_values( + self.pool.get_database_backend(), + sql, + [ + channel_id.to_proto().into(), + ], + ); + tx.execute(channel_paths_stmt).await?; + Ok((channels_to_remove.into_keys().collect(), members_to_notify)) }) .await @@ -844,13 +859,6 @@ impl Database { // channel if they've linked the channel to one where they're an admin. self.check_user_is_channel_admin(from, user, &*tx).await?; - if let Some(to) = to { - self.check_user_is_channel_admin(to, user, &*tx).await?; - - self.link_channel(from, to, &*tx).await?; - } - // The removal must come after the linking so that we don't leave - // sub channels stranded if let Some(from_parent) = from_parent { self.check_user_is_channel_admin(from_parent, user, &*tx) .await?; @@ -859,6 +867,12 @@ impl Database { .await?; } + if let Some(to) = to { + self.check_user_is_channel_admin(to, user, &*tx).await?; + + self.link_channel(from, to, &*tx).await?; + } + Ok(()) }) .await