feat: Allow manually specifying event IDs as extremities

This commit is contained in:
nexy7574 2025-08-31 22:53:58 +01:00
commit cd95f29ece
No known key found for this signature in database
2 changed files with 24 additions and 11 deletions

View file

@ -922,7 +922,11 @@ pub(super) async fn trim_memory(&self) -> Result {
} }
#[admin_command] #[admin_command]
pub(super) async fn force_append_latest_extremity(&self, room_id: OwnedRoomId) -> Result { pub(super) async fn force_append_latest_extremity(
&self,
room_id: OwnedRoomId,
event_id: Option<OwnedEventId>,
) -> Result {
let lock = self.services.rooms.state.mutex.lock(&*room_id).await; let lock = self.services.rooms.state.mutex.lock(&*room_id).await;
let mut extremities: Vec<&EventId> = self let mut extremities: Vec<&EventId> = self
.services .services
@ -932,17 +936,21 @@ pub(super) async fn force_append_latest_extremity(&self, room_id: OwnedRoomId) -
.collect() .collect()
.await; .await;
let latest_pdu = self let selected_id = if let Some(event_id) = event_id {
.services event_id
.rooms } else {
.timeline self.services
.latest_pdu_in_room(&room_id) .rooms
.await .timeline
.map_err(|_| err!(Database("Failed to find the latest PDU in database")))?; .latest_pdu_in_room(&room_id)
.await
.map_err(|_| err!(Database("Failed to find the latest PDU in database")))?
.event_id()
.to_owned()
};
let pdu_id = latest_pdu.event_id(); if !extremities.contains(&selected_id.as_ref()) {
if !extremities.contains(&pdu_id) { extremities.push(&selected_id);
extremities.push(pdu_id);
} }
self.services self.services

View file

@ -237,9 +237,14 @@ pub enum DebugCommand {
level: Option<i32>, level: Option<i32>,
}, },
/// - Forcefully add the latest known event in the specified room as a
/// forward extremity. Use with caution.
ForceAppendLatestExtremity { ForceAppendLatestExtremity {
/// The room ID /// The room ID
room_id: OwnedRoomId, room_id: OwnedRoomId,
/// If set, forcefully picks an event ID to use as an extremity. Is not
/// validated.
event_id: Option<OwnedEventId>,
}, },
/// - Developer test stubs /// - Developer test stubs