1616//! This module does not implement any of the safety checks that should be run
1717//! *before* the migration.
1818
19- use std:: {
20- collections:: { HashMap , HashSet } ,
21- pin:: pin,
22- time:: Instant ,
23- } ;
19+ use std:: { pin:: pin, time:: Instant } ;
2420
2521use chrono:: { DateTime , Utc } ;
2622use compact_str:: CompactString ;
@@ -45,7 +41,7 @@ use crate::{
4541 self , ExtractLocalpartError , FullUserId , SynapseAccessToken , SynapseDevice ,
4642 SynapseExternalId , SynapseRefreshableTokenPair , SynapseThreepid , SynapseUser ,
4743 } ,
48- SynapseReader ,
44+ HashMap , HashSet , RandomState , SynapseReader ,
4945} ;
5046
5147#[ derive( Debug , Error , ContextInto ) ]
@@ -105,7 +101,7 @@ pub async fn migrate(
105101 server_name : & str ,
106102 clock : & dyn Clock ,
107103 rng : & mut impl RngCore ,
108- provider_id_mapping : & HashMap < String , Uuid > ,
104+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
109105) -> Result < ( ) , Error > {
110106 let span = Span :: current ( ) ;
111107 span. pb_set_message ( "counting work" ) ;
@@ -159,12 +155,13 @@ pub async fn migrate(
159155
160156 // `(MAS user_id, device_id)` mapped to `compat_session` ULID
161157 let mut devices_to_compat_sessions: HashMap < ( Uuid , CompactString ) , Uuid > =
162- HashMap :: with_capacity (
158+ HashMap :: with_capacity_and_hasher (
163159 usize:: try_from ( counts. devices )
164160 . expect ( "More than usize::MAX devices — unable to handle this many!" )
165161 // Oversize the capacity, because the count is only an estimate and
166162 // we would like to avoid a reallocation
167163 * 9 / 8 ,
164+ RandomState :: default ( ) ,
168165 ) ;
169166
170167 span. pb_set_message ( "migrating access tokens" ) ;
@@ -254,8 +251,9 @@ async fn migrate_users(
254251 . with_progress_bar( user_count_hint as u64 , 10_000 ) ) ;
255252 // Oversize the capacity, because the count is only an estimate and
256253 // we would like to avoid a reallocation
257- let mut user_localparts_to_uuid = HashMap :: with_capacity ( user_count_hint * 9 / 8 ) ;
258- let mut synapse_admins = HashSet :: new ( ) ;
254+ let mut user_localparts_to_uuid =
255+ HashMap :: with_capacity_and_hasher ( user_count_hint * 9 / 8 , RandomState :: default ( ) ) ;
256+ let mut synapse_admins = HashSet :: with_hasher ( RandomState :: default ( ) ) ;
259257
260258 while let Some ( user_res) = users_stream. next ( ) . await {
261259 let user = user_res. into_synapse ( "reading user" ) ?;
@@ -406,7 +404,7 @@ async fn migrate_external_ids(
406404 server_name : & str ,
407405 rng : & mut impl RngCore ,
408406 user_localparts_to_uuid : & HashMap < CompactString , Uuid > ,
409- provider_id_mapping : & HashMap < String , Uuid > ,
407+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
410408) -> Result < ( ) , Error > {
411409 let start = Instant :: now ( ) ;
412410
0 commit comments