From 5208efcb5e04002e4e98cd70f2f10605925a5921 Mon Sep 17 00:00:00 2001 From: timedout Date: Tue, 13 Oct 2026 04:11:25 +0100 Subject: [PATCH] fix: Make migration handle excessive extremities too --- src/service/migrations.rs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/service/migrations.rs b/src/service/migrations.rs index 13733159c..7d9f1af8b 100644 --- a/src/service/migrations.rs +++ b/src/service/migrations.rs @@ -985,6 +985,7 @@ async fn fix_oauth_scope_names(services: &Services) -> Result { Ok(()) } +#[tracing::instrument(skip_all)] async fn remove_unknown_extremities(services: &Services) -> Result { services.db["roomid_pduleaves"] .keys() @@ -1005,27 +1006,36 @@ async fn remove_unknown_extremities(services: &Services) -> Result { Ok(()) } +#[tracing::instrument(skip_all)] async fn consistency_check_extremity_tracker(services: &Services) -> Result { let mut rooms = services.rooms.metadata.iter_ids(); // For every room the server is a member of, while let Some(room_id) = rooms.next().await { // If this room has no extremities, re-calculate - if services + let extremity_count = services .rooms .state .get_forward_extremities(&room_id) .count() - .await - >= 1 + .await; + + if extremity_count > 20 { - continue; + warn!(%extremity_count, "Room {room_id} has an abnormal number of forward extremities, attempting to re-calculate to a sane value. This might take a while."); + services + .rooms + .state + .get_forward_extremities(&room_id) + .ready_for_each(|event_id| services.rooms.state.remove_forward_extremity(&room_id, &event_id)) + .await; + } else if extremity_count == 0 { + warn!( + "Room {room_id} is missing extremity information, recalculating. This may take a \ + long time if this room is old." + ); } - warn!( - "Room {room_id} is missing extremity information, recalculating. This may take a \ - long time if this room is old." - ); services .rooms .timeline