16
16
//! This module does not implement any of the safety checks that should be run
17
17
//! *before* the migration.
18
18
19
- use std:: {
20
- collections:: { HashMap , HashSet } ,
21
- pin:: pin,
22
- time:: Instant ,
23
- } ;
19
+ use std:: { pin:: pin, time:: Instant } ;
24
20
25
21
use chrono:: { DateTime , Utc } ;
26
22
use compact_str:: CompactString ;
@@ -45,7 +41,7 @@ use crate::{
45
41
self , ExtractLocalpartError , FullUserId , SynapseAccessToken , SynapseDevice ,
46
42
SynapseExternalId , SynapseRefreshableTokenPair , SynapseThreepid , SynapseUser ,
47
43
} ,
48
- SynapseReader ,
44
+ HashMap , HashSet , RandomState , SynapseReader ,
49
45
} ;
50
46
51
47
#[ derive( Debug , Error , ContextInto ) ]
@@ -105,7 +101,7 @@ pub async fn migrate(
105
101
server_name : & str ,
106
102
clock : & dyn Clock ,
107
103
rng : & mut impl RngCore ,
108
- provider_id_mapping : & HashMap < String , Uuid > ,
104
+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
109
105
) -> Result < ( ) , Error > {
110
106
let span = Span :: current ( ) ;
111
107
span. pb_set_message ( "counting work" ) ;
@@ -159,12 +155,13 @@ pub async fn migrate(
159
155
160
156
// `(MAS user_id, device_id)` mapped to `compat_session` ULID
161
157
let mut devices_to_compat_sessions: HashMap < ( Uuid , CompactString ) , Uuid > =
162
- HashMap :: with_capacity (
158
+ HashMap :: with_capacity_and_hasher (
163
159
usize:: try_from ( counts. devices )
164
160
. expect ( "More than usize::MAX devices — unable to handle this many!" )
165
161
// Oversize the capacity, because the count is only an estimate and
166
162
// we would like to avoid a reallocation
167
163
* 9 / 8 ,
164
+ RandomState :: default ( ) ,
168
165
) ;
169
166
170
167
span. pb_set_message ( "migrating access tokens" ) ;
@@ -254,8 +251,9 @@ async fn migrate_users(
254
251
. with_progress_bar( user_count_hint as u64 , 10_000 ) ) ;
255
252
// Oversize the capacity, because the count is only an estimate and
256
253
// 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 ( ) ) ;
259
257
260
258
while let Some ( user_res) = users_stream. next ( ) . await {
261
259
let user = user_res. into_synapse ( "reading user" ) ?;
@@ -406,7 +404,7 @@ async fn migrate_external_ids(
406
404
server_name : & str ,
407
405
rng : & mut impl RngCore ,
408
406
user_localparts_to_uuid : & HashMap < CompactString , Uuid > ,
409
- provider_id_mapping : & HashMap < String , Uuid > ,
407
+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
410
408
) -> Result < ( ) , Error > {
411
409
let start = Instant :: now ( ) ;
412
410
0 commit comments