1111//! This module does not implement any of the safety checks that should be run
1212//! *before* the migration.
1313
14- use std:: {
15- collections:: { HashMap , HashSet } ,
16- pin:: pin,
17- time:: Instant ,
18- } ;
14+ use std:: { pin:: pin, time:: Instant } ;
1915
2016use chrono:: { DateTime , Utc } ;
2117use compact_str:: CompactString ;
@@ -40,7 +36,7 @@ use crate::{
4036 self , ExtractLocalpartError , FullUserId , SynapseAccessToken , SynapseDevice ,
4137 SynapseExternalId , SynapseRefreshableTokenPair , SynapseThreepid , SynapseUser ,
4238 } ,
43- SynapseReader ,
39+ HashMap , HashSet , RandomState , SynapseReader ,
4440} ;
4541
4642#[ derive( Debug , Error , ContextInto ) ]
@@ -100,7 +96,7 @@ pub async fn migrate(
10096 server_name : & str ,
10197 clock : & dyn Clock ,
10298 rng : & mut impl RngCore ,
103- provider_id_mapping : & HashMap < String , Uuid > ,
99+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
104100) -> Result < ( ) , Error > {
105101 let span = Span :: current ( ) ;
106102 span. pb_set_message ( "counting work" ) ;
@@ -154,12 +150,13 @@ pub async fn migrate(
154150
155151 // `(MAS user_id, device_id)` mapped to `compat_session` ULID
156152 let mut devices_to_compat_sessions: HashMap < ( Uuid , CompactString ) , Uuid > =
157- HashMap :: with_capacity (
153+ HashMap :: with_capacity_and_hasher (
158154 usize:: try_from ( counts. devices )
159155 . expect ( "More than usize::MAX devices — unable to handle this many!" )
160156 // Oversize the capacity, because the count is only an estimate and
161157 // we would like to avoid a reallocation
162158 * 9 / 8 ,
159+ RandomState :: default ( ) ,
163160 ) ;
164161
165162 span. pb_set_message ( "migrating access tokens" ) ;
@@ -249,8 +246,9 @@ async fn migrate_users(
249246 . with_progress_bar( user_count_hint as u64 , 10_000 ) ) ;
250247 // Oversize the capacity, because the count is only an estimate and
251248 // we would like to avoid a reallocation
252- let mut user_localparts_to_uuid = HashMap :: with_capacity ( user_count_hint * 9 / 8 ) ;
253- let mut synapse_admins = HashSet :: new ( ) ;
249+ let mut user_localparts_to_uuid =
250+ HashMap :: with_capacity_and_hasher ( user_count_hint * 9 / 8 , RandomState :: default ( ) ) ;
251+ let mut synapse_admins = HashSet :: with_hasher ( RandomState :: default ( ) ) ;
254252
255253 while let Some ( user_res) = users_stream. next ( ) . await {
256254 let user = user_res. into_synapse ( "reading user" ) ?;
@@ -401,7 +399,7 @@ async fn migrate_external_ids(
401399 server_name : & str ,
402400 rng : & mut impl RngCore ,
403401 user_localparts_to_uuid : & HashMap < CompactString , Uuid > ,
404- provider_id_mapping : & HashMap < String , Uuid > ,
402+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
405403) -> Result < ( ) , Error > {
406404 let start = Instant :: now ( ) ;
407405
0 commit comments