From 39023b5ed3c786803da8cfb5aab8f9e7d5e8f75a Mon Sep 17 00:00:00 2001 From: nexy7574 Date: Sun, 31 Aug 2025 21:51:04 +0100 Subject: [PATCH] feat: Add force-set-latest-extremity command --- src/admin/debug/commands.rs | 38 +++++++++++++++++++++++++++++++++++++ src/admin/debug/mod.rs | 5 +++++ 2 files changed, 43 insertions(+) diff --git a/src/admin/debug/commands.rs b/src/admin/debug/commands.rs index 81b0e9da..e6d92fca 100644 --- a/src/admin/debug/commands.rs +++ b/src/admin/debug/commands.rs @@ -920,3 +920,41 @@ pub(super) async fn trim_memory(&self) -> Result { writeln!(self, "done").await } + +#[admin_command] +pub(super) async fn force_append_latest_extremity(&self, room_id: OwnedRoomId) -> Result { + let lock = self.services.rooms.state.mutex.lock(&*room_id).await; + let mut extremities: Vec<&EventId> = self + .services + .rooms + .state + .get_forward_extremities(&room_id) + .collect() + .await; + + let latest_pdu = self + .services + .rooms + .timeline + .latest_pdu_in_room(&room_id) + .await + .map_err(|_| err!(Database("Failed to find the latest PDU in database")))?; + + let pdu_id = latest_pdu.event_id(); + if !extremities.contains(&pdu_id) { + extremities.push(pdu_id); + } + + self.services + .rooms + .state + .set_forward_extremities(&room_id, extremities.iter().copied(), &lock) + .await; + + self.write_str(&format!( + "Successfully retained the following {} forward extremities in room \ + {room_id}:\n```\n{extremities:?}\n```", + extremities.len() + )) + .await +} diff --git a/src/admin/debug/mod.rs b/src/admin/debug/mod.rs index 7a0769ab..b924bf4f 100644 --- a/src/admin/debug/mod.rs +++ b/src/admin/debug/mod.rs @@ -237,6 +237,11 @@ pub enum DebugCommand { level: Option, }, + ForceAppendLatestExtremity { + /// The room ID + room_id: OwnedRoomId, + }, + /// - Developer test stubs #[command(subcommand)] #[allow(non_snake_case)]