improvement: try to load missing prev events

This commit is contained in:
Timo Kösters 2021-08-09 19:15:14 +02:00
parent d2f406e0e8
commit 260db9fcc7
No known key found for this signature in database
GPG key ID: 356E705610F626D5
2 changed files with 71 additions and 27 deletions

View file

@ -280,6 +280,24 @@ impl Rooms {
.is_some())
}
/// Checks if a room exists.
pub fn first_pdu_in_room(&self, room_id: &RoomId) -> Result<Option<Arc<PduEvent>>> {
let mut prefix = room_id.as_bytes().to_vec();
prefix.push(0xff);
// Look for PDUs in that room.
self.pduid_pdu
.iter_from(&prefix, false)
.filter(|(k, _)| k.starts_with(&prefix))
.map(|(_, pdu)| {
serde_json::from_slice(&pdu)
.map_err(|_| Error::bad_database("Invalid first PDU in db."))
.map(Arc::new)
})
.next()
.transpose()
}
/// Force the creation of a new StateHash and insert it into the db.
///
/// Whatever `state` is supplied to `force_state` __is__ the current room state snapshot.