From ad792f4565bfd005c8c9ef2023225a805f4eeb89 Mon Sep 17 00:00:00 2001 From: strawberry Date: Sun, 14 Jan 2024 00:03:59 -0500 Subject: [PATCH] oops dedup only works on consecutive elements Signed-off-by: strawberry --- src/api/client_server/alias.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/api/client_server/alias.rs b/src/api/client_server/alias.rs index 0d8f1801..1c3ff231 100644 --- a/src/api/client_server/alias.rs +++ b/src/api/client_server/alias.rs @@ -103,9 +103,6 @@ pub(crate) async fn get_alias_helper( servers.push(extra_servers); } - // shuffle list of servers randomly - servers.shuffle(&mut rand::thread_rng()); - // insert our server as the very first choice if in list if let Some(server_index) = servers .clone() @@ -116,8 +113,12 @@ pub(crate) async fn get_alias_helper( servers.insert(0, services().globals.server_name().to_owned()); } + servers.sort_unstable(); servers.dedup(); + // shuffle list of servers randomly after sort and dedupe + servers.shuffle(&mut rand::thread_rng()); + return Ok(get_alias::v3::Response::new(room_id, servers)); } @@ -188,9 +189,6 @@ pub(crate) async fn get_alias_helper( servers.push(extra_servers); } - // shuffle list of servers randomly - servers.shuffle(&mut rand::thread_rng()); - // insert our server as the very first choice if in list if let Some(server_index) = servers .clone() @@ -201,7 +199,11 @@ pub(crate) async fn get_alias_helper( servers.insert(0, services().globals.server_name().to_owned()); } + servers.sort_unstable(); servers.dedup(); + // shuffle list of servers randomly after sort and dedupe + servers.shuffle(&mut rand::thread_rng()); + Ok(get_alias::v3::Response::new(room_id, servers)) }