11
11
//! This module does not implement any of the safety checks that should be run
12
12
//! *before* the migration.
13
13
14
- use std:: {
15
- collections:: { HashMap , HashSet } ,
16
- pin:: pin,
17
- time:: Instant ,
18
- } ;
14
+ use std:: { pin:: pin, time:: Instant } ;
19
15
20
16
use chrono:: { DateTime , Utc } ;
21
17
use compact_str:: CompactString ;
@@ -40,7 +36,7 @@ use crate::{
40
36
self , ExtractLocalpartError , FullUserId , SynapseAccessToken , SynapseDevice ,
41
37
SynapseExternalId , SynapseRefreshableTokenPair , SynapseThreepid , SynapseUser ,
42
38
} ,
43
- SynapseReader ,
39
+ HashMap , HashSet , RandomState , SynapseReader ,
44
40
} ;
45
41
46
42
#[ derive( Debug , Error , ContextInto ) ]
@@ -100,7 +96,7 @@ pub async fn migrate(
100
96
server_name : & str ,
101
97
clock : & dyn Clock ,
102
98
rng : & mut impl RngCore ,
103
- provider_id_mapping : & HashMap < String , Uuid > ,
99
+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
104
100
) -> Result < ( ) , Error > {
105
101
let span = Span :: current ( ) ;
106
102
span. pb_set_message ( "counting work" ) ;
@@ -154,12 +150,13 @@ pub async fn migrate(
154
150
155
151
// `(MAS user_id, device_id)` mapped to `compat_session` ULID
156
152
let mut devices_to_compat_sessions: HashMap < ( Uuid , CompactString ) , Uuid > =
157
- HashMap :: with_capacity (
153
+ HashMap :: with_capacity_and_hasher (
158
154
usize:: try_from ( counts. devices )
159
155
. expect ( "More than usize::MAX devices — unable to handle this many!" )
160
156
// Oversize the capacity, because the count is only an estimate and
161
157
// we would like to avoid a reallocation
162
158
* 9 / 8 ,
159
+ RandomState :: default ( ) ,
163
160
) ;
164
161
165
162
span. pb_set_message ( "migrating access tokens" ) ;
@@ -249,8 +246,9 @@ async fn migrate_users(
249
246
. with_progress_bar( user_count_hint as u64 , 10_000 ) ) ;
250
247
// Oversize the capacity, because the count is only an estimate and
251
248
// 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 ( ) ) ;
254
252
255
253
while let Some ( user_res) = users_stream. next ( ) . await {
256
254
let user = user_res. into_synapse ( "reading user" ) ?;
@@ -401,7 +399,7 @@ async fn migrate_external_ids(
401
399
server_name : & str ,
402
400
rng : & mut impl RngCore ,
403
401
user_localparts_to_uuid : & HashMap < CompactString , Uuid > ,
404
- provider_id_mapping : & HashMap < String , Uuid > ,
402
+ provider_id_mapping : & std :: collections :: HashMap < String , Uuid > ,
405
403
) -> Result < ( ) , Error > {
406
404
let start = Instant :: now ( ) ;
407
405
0 commit comments