Skip to content

Commit f483c5c

Browse files
committed
Have a single struct with all the maps, unify signatures
1 parent 65562f9 commit f483c5c

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

crates/syn2mas/src/migration.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,16 @@ pub async fn migrate(
165165

166166
span.pb_set_message("migrating threepids");
167167
span.pb_inc(1);
168-
let mas = migrate_threepids(&mut synapse, mas, counts.threepids, rng, &state).await?;
168+
let (state, mas) = migrate_threepids(&mut synapse, mas, counts.threepids, rng, state).await?;
169+
169170
span.pb_set_message("migrating user external IDs");
170171
span.pb_inc(1);
171-
let mas = migrate_external_ids(&mut synapse, mas, counts.external_ids, rng, &state).await?;
172+
let (state, mas) =
173+
migrate_external_ids(&mut synapse, mas, counts.external_ids, rng, state).await?;
172174

173175
span.pb_set_message("migrating access tokens");
174176
span.pb_inc(1);
175-
let (mut state, mas) = migrate_unrefreshable_access_tokens(
177+
let (state, mas) = migrate_unrefreshable_access_tokens(
176178
&mut synapse,
177179
mas,
178180
counts.access_tokens,
@@ -184,13 +186,13 @@ pub async fn migrate(
184186

185187
span.pb_set_message("migrating refresh tokens");
186188
span.pb_inc(1);
187-
let mas = migrate_refreshable_token_pairs(
189+
let (state, mas) = migrate_refreshable_token_pairs(
188190
&mut synapse,
189191
mas,
190192
counts.refresh_tokens,
191193
clock,
192194
rng,
193-
&mut state,
195+
state,
194196
)
195197
.await?;
196198

@@ -296,8 +298,8 @@ async fn migrate_threepids(
296298
mut mas: MasWriter,
297299
count_hint: usize,
298300
rng: &mut impl RngCore,
299-
state: &MigrationState,
300-
) -> Result<MasWriter, Error> {
301+
state: MigrationState,
302+
) -> Result<(MigrationState, MasWriter), Error> {
301303
let start = Instant::now();
302304

303305
let mut email_buffer = MasWriteBuffer::new(&mas, MasWriter::write_email_threepids);
@@ -380,7 +382,7 @@ async fn migrate_threepids(
380382
Instant::now().duration_since(start).as_secs_f64()
381383
);
382384

383-
Ok(mas)
385+
Ok((state, mas))
384386
}
385387

386388
/// # Parameters
@@ -393,8 +395,8 @@ async fn migrate_external_ids(
393395
mut mas: MasWriter,
394396
count_hint: usize,
395397
rng: &mut impl RngCore,
396-
state: &MigrationState,
397-
) -> Result<MasWriter, Error> {
398+
state: MigrationState,
399+
) -> Result<(MigrationState, MasWriter), Error> {
398400
let start = Instant::now();
399401

400402
let mut write_buffer = MasWriteBuffer::new(&mas, MasWriter::write_upstream_oauth_links);
@@ -461,7 +463,7 @@ async fn migrate_external_ids(
461463
Instant::now().duration_since(start).as_secs_f64()
462464
);
463465

464-
Ok(mas)
466+
Ok((state, mas))
465467
}
466468

467469
/// Migrate devices from Synapse to MAS (as compat sessions).
@@ -593,7 +595,6 @@ async fn migrate_devices(
593595
/// Migrates unrefreshable access tokens (those without an associated refresh
594596
/// token). Some of these may be deviceless.
595597
#[tracing::instrument(skip_all, fields(indicatif.pb_show), level = Level::INFO)]
596-
#[allow(clippy::too_many_arguments, clippy::type_complexity)]
597598
async fn migrate_unrefreshable_access_tokens(
598599
synapse: &mut SynapseReader<'_>,
599600
mut mas: MasWriter,
@@ -735,8 +736,8 @@ async fn migrate_refreshable_token_pairs(
735736
count_hint: usize,
736737
clock: &dyn Clock,
737738
rng: &mut impl RngCore,
738-
state: &mut MigrationState,
739-
) -> Result<MasWriter, Error> {
739+
mut state: MigrationState,
740+
) -> Result<(MigrationState, MasWriter), Error> {
740741
let start = Instant::now();
741742

742743
let mut token_stream = pin!(synapse
@@ -833,7 +834,7 @@ async fn migrate_refreshable_token_pairs(
833834
Instant::now().duration_since(start).as_secs_f64()
834835
);
835836

836-
Ok(mas)
837+
Ok((state, mas))
837838
}
838839

839840
fn transform_user(

crates/syn2mas/src/synapse_reader/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl<'conn> SynapseReader<'conn> {
348348
// On matrix.org, counting users and devices properly takes around 1m10s,
349349
// which is unnecessary extra downtime during the migration, just to
350350
// show a more accurate progress bar and size a hash map accurately.
351-
let users: usize = sqlx::query_scalar::<_, i64>(
351+
let users = sqlx::query_scalar::<_, i64>(
352352
"
353353
SELECT reltuples::bigint AS estimate FROM pg_class WHERE oid = 'users'::regclass;
354354
",

0 commit comments

Comments
 (0)