improvement: randomize server order for alias joins

This commit is contained in:
Timo Kösters 2023-06-28 17:41:55 +02:00
parent 3a1a72df98
commit fd1ccbd3ad
No known key found for this signature in database
GPG Key ID: 0B25E636FBA7E4CB
2 changed files with 6 additions and 5 deletions

View File

@ -1,4 +1,5 @@
use crate::{services, Error, Result, Ruma}; use crate::{services, Error, Result, Ruma};
use rand::seq::SliceRandom;
use regex::Regex; use regex::Regex;
use ruma::{ use ruma::{
api::{ api::{
@ -90,10 +91,10 @@ pub(crate) async fn get_alias_helper(
) )
.await?; .await?;
return Ok(get_alias::v3::Response::new( let mut servers = response.servers;
response.room_id, servers.shuffle(&mut rand::thread_rng());
response.servers,
)); return Ok(get_alias::v3::Response::new(response.room_id, servers));
} }
let mut room_id = None; let mut room_id = None;

View File

@ -112,7 +112,7 @@ pub async fn join_room_by_id_or_alias_route(
Err(room_alias) => { Err(room_alias) => {
let response = get_alias_helper(room_alias).await?; let response = get_alias_helper(room_alias).await?;
(response.servers.into_iter().collect(), response.room_id) (response.servers, response.room_id)
} }
}; };