feat: Add force-set-latest-extremity command

This commit is contained in:
nexy7574 2025-08-31 21:51:04 +01:00
commit 39023b5ed3
No known key found for this signature in database
2 changed files with 43 additions and 0 deletions

View file

@ -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
}

View file

@ -237,6 +237,11 @@ pub enum DebugCommand {
level: Option<i32>,
},
ForceAppendLatestExtremity {
/// The room ID
room_id: OwnedRoomId,
},
/// - Developer test stubs
#[command(subcommand)]
#[allow(non_snake_case)]