|
|
|
@ -385,7 +385,7 @@ impl Rooms {
|
|
|
|
|
self.save_state_from_diff(
|
|
|
|
|
new_shortstatehash,
|
|
|
|
|
statediffnew.clone(),
|
|
|
|
|
statediffremoved.clone(),
|
|
|
|
|
statediffremoved,
|
|
|
|
|
2, // every state change is 2 event changes on average
|
|
|
|
|
states_parents,
|
|
|
|
|
)?;
|
|
|
|
@ -497,8 +497,7 @@ impl Rooms {
|
|
|
|
|
|
|
|
|
|
Ok(response)
|
|
|
|
|
} else {
|
|
|
|
|
let mut response = Vec::new();
|
|
|
|
|
response.push((shortstatehash, added.clone(), added, removed));
|
|
|
|
|
let response = vec![(shortstatehash, added.clone(), added, removed)];
|
|
|
|
|
self.stateinfo_cache
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
@ -609,7 +608,7 @@ impl Rooms {
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if parent_states.len() == 0 {
|
|
|
|
|
if parent_states.is_empty() {
|
|
|
|
|
// There is no parent layer, create a new state
|
|
|
|
|
let mut value = 0_u64.to_be_bytes().to_vec(); // 0 means no parent
|
|
|
|
|
for new in &statediffnew {
|
|
|
|
@ -689,7 +688,7 @@ impl Rooms {
|
|
|
|
|
state_hash: &StateHashId,
|
|
|
|
|
globals: &super::globals::Globals,
|
|
|
|
|
) -> Result<(u64, bool)> {
|
|
|
|
|
Ok(match self.statehash_shortstatehash.get(&state_hash)? {
|
|
|
|
|
Ok(match self.statehash_shortstatehash.get(state_hash)? {
|
|
|
|
|
Some(shortstatehash) => (
|
|
|
|
|
utils::u64_from_bytes(&shortstatehash)
|
|
|
|
|
.map_err(|_| Error::bad_database("Invalid shortstatehash in db."))?,
|
|
|
|
@ -698,7 +697,7 @@ impl Rooms {
|
|
|
|
|
None => {
|
|
|
|
|
let shortstatehash = globals.next_count()?;
|
|
|
|
|
self.statehash_shortstatehash
|
|
|
|
|
.insert(&state_hash, &shortstatehash.to_be_bytes())?;
|
|
|
|
|
.insert(state_hash, &shortstatehash.to_be_bytes())?;
|
|
|
|
|
(shortstatehash, false)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
@ -1768,8 +1767,8 @@ impl Rooms {
|
|
|
|
|
};
|
|
|
|
|
self.save_state_from_diff(
|
|
|
|
|
shortstatehash,
|
|
|
|
|
statediffnew.clone(),
|
|
|
|
|
statediffremoved.clone(),
|
|
|
|
|
statediffnew,
|
|
|
|
|
statediffremoved,
|
|
|
|
|
1_000_000, // high number because no state will be based on this one
|
|
|
|
|
states_parents,
|
|
|
|
|
)?;
|
|
|
|
@ -1914,15 +1913,14 @@ impl Rooms {
|
|
|
|
|
let mut key = shortroomid.to_be_bytes().to_vec();
|
|
|
|
|
key.extend_from_slice(&token.to_be_bytes());
|
|
|
|
|
|
|
|
|
|
Ok(self
|
|
|
|
|
.roomsynctoken_shortstatehash
|
|
|
|
|
self.roomsynctoken_shortstatehash
|
|
|
|
|
.get(&key)?
|
|
|
|
|
.map(|bytes| {
|
|
|
|
|
utils::u64_from_bytes(&bytes).map_err(|_| {
|
|
|
|
|
Error::bad_database("Invalid shortstatehash in roomsynctoken_shortstatehash")
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
.transpose()?)
|
|
|
|
|
.transpose()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Creates a new persisted data unit and adds it to a room.
|
|
|
|
@ -2475,8 +2473,8 @@ impl Rooms {
|
|
|
|
|
self.roomuserid_leftcount.remove(&roomuser_id)?;
|
|
|
|
|
}
|
|
|
|
|
member::MembershipState::Leave | member::MembershipState::Ban => {
|
|
|
|
|
if update_joined_count {
|
|
|
|
|
if self
|
|
|
|
|
if update_joined_count
|
|
|
|
|
&& self
|
|
|
|
|
.room_members(room_id)
|
|
|
|
|
.chain(self.room_members_invited(room_id))
|
|
|
|
|
.filter_map(|r| r.ok())
|
|
|
|
@ -2485,7 +2483,6 @@ impl Rooms {
|
|
|
|
|
self.roomserverids.remove(&roomserver_id)?;
|
|
|
|
|
self.serverroomids.remove(&serverroom_id)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
self.userroomid_leftstate.insert(
|
|
|
|
|
&userroom_id,
|
|
|
|
|
&serde_json::to_vec(&Vec::<Raw<AnySyncStateEvent>>::new()).unwrap(),
|
|
|
|
@ -2621,8 +2618,7 @@ impl Rooms {
|
|
|
|
|
|
|
|
|
|
if let Some(b) = maybe {
|
|
|
|
|
Ok(b)
|
|
|
|
|
} else {
|
|
|
|
|
if let Some(namespaces) = appservice.1.get("namespaces") {
|
|
|
|
|
} else if let Some(namespaces) = appservice.1.get("namespaces") {
|
|
|
|
|
let users = namespaces
|
|
|
|
|
.get("users")
|
|
|
|
|
.and_then(|users| users.as_sequence())
|
|
|
|
@ -2661,7 +2657,6 @@ impl Rooms {
|
|
|
|
|
Ok(false)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tracing::instrument(skip(self, db))]
|
|
|
|
|
pub async fn leave_room(
|
|
|
|
@ -3452,10 +3447,7 @@ impl Rooms {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cache in RAM
|
|
|
|
|
self.auth_chain_cache
|
|
|
|
|
.lock()
|
|
|
|
|
.unwrap()
|
|
|
|
|
.insert(key.clone(), chain);
|
|
|
|
|
self.auth_chain_cache.lock().unwrap().insert(key, chain);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|