oops dedup only works on consecutive elements

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-01-14 00:03:59 -05:00 committed by June
parent 52884abff6
commit ad792f4565

View file

@ -103,9 +103,6 @@ pub(crate) async fn get_alias_helper(
servers.push(extra_servers); 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 // insert our server as the very first choice if in list
if let Some(server_index) = servers if let Some(server_index) = servers
.clone() .clone()
@ -116,8 +113,12 @@ pub(crate) async fn get_alias_helper(
servers.insert(0, services().globals.server_name().to_owned()); servers.insert(0, services().globals.server_name().to_owned());
} }
servers.sort_unstable();
servers.dedup(); 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)); 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); 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 // insert our server as the very first choice if in list
if let Some(server_index) = servers if let Some(server_index) = servers
.clone() .clone()
@ -201,7 +199,11 @@ pub(crate) async fn get_alias_helper(
servers.insert(0, services().globals.server_name().to_owned()); servers.insert(0, services().globals.server_name().to_owned());
} }
servers.sort_unstable();
servers.dedup(); 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)) Ok(get_alias::v3::Response::new(room_id, servers))
} }