From f27d59896fa02446e50e96a20907f17241ad46cd Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Mon, 26 Feb 2024 10:07:22 -0700 Subject: [PATCH] unique channel names (#8439) Before this change duplicate channels were ordered arbitrarily, which put the collab channel in an inconsistent state. Release Notes: - Fixed duplicate channel names appearing in the collab sidebar. --- crates/channel/src/channel_store/channel_index.rs | 9 ++++++--- .../migrations/20240226164505_unique_channel_names.sql | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) create mode 100644 crates/collab/migrations/20240226164505_unique_channel_names.sql diff --git a/crates/channel/src/channel_store/channel_index.rs b/crates/channel/src/channel_store/channel_index.rs index e70b3e4c46352b039f3b0bb8c58d7dcdcc1a275d..7e6ddd297004199a065f7cc382082477fc406787 100644 --- a/crates/channel/src/channel_store/channel_index.rs +++ b/crates/channel/src/channel_store/channel_index.rs @@ -94,14 +94,17 @@ impl<'a> Drop for ChannelPathsInsertGuard<'a> { fn channel_path_sorting_key<'a>( id: ChannelId, channels_by_id: &'a BTreeMap>, -) -> impl Iterator { +) -> impl Iterator { let (parent_path, name) = channels_by_id .get(&id) .map_or((&[] as &[_], None), |channel| { - (channel.parent_path.as_slice(), Some(channel.name.as_ref())) + ( + channel.parent_path.as_slice(), + Some((channel.name.as_ref(), channel.id)), + ) }); parent_path .iter() - .filter_map(|id| Some(channels_by_id.get(id)?.name.as_ref())) + .filter_map(|id| Some((channels_by_id.get(id)?.name.as_ref(), *id))) .chain(name) } diff --git a/crates/collab/migrations/20240226164505_unique_channel_names.sql b/crates/collab/migrations/20240226164505_unique_channel_names.sql new file mode 100644 index 0000000000000000000000000000000000000000..9e6a0d876180bf61d565e49b96d0fd05c7ce51f7 --- /dev/null +++ b/crates/collab/migrations/20240226164505_unique_channel_names.sql @@ -0,0 +1,3 @@ +-- Add migration script here + +CREATE UNIQUE INDEX uix_channels_parent_path_name ON channels(parent_path, name) WHERE (parent_path IS NOT NULL);