messing around with arcs

This commit is contained in:
Timo Kösters 2022-10-05 15:33:57 +02:00 committed by Nyaaori
parent face766e0f
commit cff52d7ebb
No known key found for this signature in database
GPG key ID: E7819C3ED4D1F82E
77 changed files with 598 additions and 434 deletions

View file

@ -1,9 +1,10 @@
use std::sync::Arc;
use std::{sync::MutexGuard, collections::HashSet};
use std::collections::HashSet;
use crate::Result;
use ruma::{EventId, RoomId};
use tokio::sync::MutexGuard;
pub trait Data {
pub trait Data: Send + Sync {
/// Returns the last state hash key added to the db for the given room.
fn get_room_shortstatehash(&self, room_id: &RoomId) -> Result<Option<u64>>;
@ -21,7 +22,7 @@ pub trait Data {
/// Replace the forward extremities of the room.
fn set_forward_extremities<'a>(&self,
room_id: &RoomId,
event_ids: &dyn Iterator<Item = &'a EventId>,
event_ids: &mut dyn Iterator<Item = &'a EventId>,
_mutex_lock: &MutexGuard<'_, ()>, // Take mutex guard to make sure users get the room state mutex
) -> Result<()>;
}

View file

@ -16,7 +16,7 @@ pub struct Service {
impl Service {
/// Set the room to the given statehash and update caches.
pub fn force_state(
pub async fn force_state(
&self,
room_id: &RoomId,
shortstatehash: u64,
@ -28,7 +28,7 @@ impl Service {
.roomid_mutex_state
.write()
.unwrap()
.entry(body.room_id.to_owned())
.entry(room_id.to_owned())
.or_default(),
);
let state_lock = mutex_state.lock().await;
@ -74,10 +74,10 @@ impl Service {
Err(_) => continue,
};
services().room.state_cache.update_membership(room_id, &user_id, membership, &pdu.sender, None, false)?;
services().rooms.state_cache.update_membership(room_id, &user_id, membership, &pdu.sender, None, false)?;
}
services().room.state_cache.update_joined_count(room_id)?;
services().rooms.state_cache.update_joined_count(room_id)?;
self.db.set_room_state(room_id, shortstatehash, &state_lock);