|
|
|
|
@ -36,16 +36,6 @@ use super::admin::AdminCommand;
@@ -36,16 +36,6 @@ use super::admin::AdminCommand;
|
|
|
|
|
/// hashing the entire state.
|
|
|
|
|
pub type StateHashId = IVec; |
|
|
|
|
|
|
|
|
|
/// An enum that represents the two valid states when searching
|
|
|
|
|
/// for an events "parent".
|
|
|
|
|
///
|
|
|
|
|
/// An events parent is any event we are aware of that is part of
|
|
|
|
|
/// the events `prev_events` array.
|
|
|
|
|
pub(crate) enum ClosestParent { |
|
|
|
|
Append, |
|
|
|
|
Insert(u64), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#[derive(Clone)] |
|
|
|
|
pub struct Rooms { |
|
|
|
|
pub edus: edus::RoomEdus, |
|
|
|
|
@ -411,54 +401,6 @@ impl Rooms {
@@ -411,54 +401,6 @@ impl Rooms {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Recursively search for a PDU from our DB that is also in the
|
|
|
|
|
/// `prev_events` field of the incoming PDU.
|
|
|
|
|
///
|
|
|
|
|
/// First we check if the last PDU inserted to the given room is a parent
|
|
|
|
|
/// if not we recursively check older `prev_events` to insert the incoming
|
|
|
|
|
/// event after.
|
|
|
|
|
pub(crate) fn get_latest_pduid_before( |
|
|
|
|
&self, |
|
|
|
|
room: &RoomId, |
|
|
|
|
incoming_prev_ids: &[EventId], |
|
|
|
|
their_state: &BTreeMap<EventId, Arc<StateEvent>>, |
|
|
|
|
) -> Result<Option<ClosestParent>> { |
|
|
|
|
match self.pduid_pdu.scan_prefix(room.as_bytes()).last() { |
|
|
|
|
Some(Ok(val)) |
|
|
|
|
if incoming_prev_ids.contains( |
|
|
|
|
&serde_json::from_slice::<PduEvent>(&val.1) |
|
|
|
|
.map_err(|_| { |
|
|
|
|
Error::bad_database("last DB entry contains invalid PDU bytes") |
|
|
|
|
})? |
|
|
|
|
.event_id, |
|
|
|
|
) => |
|
|
|
|
{ |
|
|
|
|
Ok(Some(ClosestParent::Append)) |
|
|
|
|
} |
|
|
|
|
_ => { |
|
|
|
|
let mut prev_ids = incoming_prev_ids.to_vec(); |
|
|
|
|
while let Some(id) = prev_ids.pop() { |
|
|
|
|
match self.get_pdu_id(&id)? { |
|
|
|
|
Some(pdu_id) => { |
|
|
|
|
return Ok(Some(ClosestParent::Insert(self.pdu_count(&pdu_id)?))); |
|
|
|
|
} |
|
|
|
|
None => { |
|
|
|
|
prev_ids.extend(their_state.get(&id).map_or( |
|
|
|
|
Err(Error::BadServerResponse( |
|
|
|
|
"Failed to find previous event for PDU in state", |
|
|
|
|
)), |
|
|
|
|
// `prev_event_ids` will return an empty Vec instead of failing
|
|
|
|
|
// so it works perfect for our use here
|
|
|
|
|
|pdu| Ok(pdu.prev_event_ids()), |
|
|
|
|
)?); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Ok(None) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Returns the leaf pdus of a room.
|
|
|
|
|
pub fn get_pdu_leaves(&self, room_id: &RoomId) -> Result<Vec<EventId>> { |
|
|
|
|
let mut prefix = room_id.as_bytes().to_vec(); |
|
|
|
|
|