improvement: save member count + sled fixes
This commit is contained in:
parent
b813c34642
commit
902404d48d
6 changed files with 65 additions and 19 deletions
|
@ -55,6 +55,7 @@ pub struct Rooms {
|
|||
|
||||
pub(super) userroomid_joined: Arc<dyn Tree>,
|
||||
pub(super) roomuserid_joined: Arc<dyn Tree>,
|
||||
pub(super) roomid_joinedcount: Arc<dyn Tree>,
|
||||
pub(super) roomuseroncejoinedids: Arc<dyn Tree>,
|
||||
pub(super) userroomid_invitestate: Arc<dyn Tree>, // InviteState = Vec<Raw<Pdu>>
|
||||
pub(super) roomuserid_invitecount: Arc<dyn Tree>, // InviteCount = Count
|
||||
|
@ -1906,9 +1907,18 @@ impl Rooms {
|
|||
_ => {}
|
||||
}
|
||||
|
||||
self.update_joined_count(room_id)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn update_joined_count(&self, room_id: &RoomId) -> Result<()> {
|
||||
self.roomid_joinedcount.insert(
|
||||
room_id.as_bytes(),
|
||||
&(self.room_members(&room_id).count() as u64).to_be_bytes(),
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn leave_room(
|
||||
&self,
|
||||
user_id: &UserId,
|
||||
|
@ -2370,6 +2380,17 @@ impl Rooms {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn room_joined_count(&self, room_id: &RoomId) -> Result<Option<u64>> {
|
||||
Ok(self
|
||||
.roomid_joinedcount
|
||||
.get(room_id.as_bytes())?
|
||||
.map(|b| {
|
||||
utils::u64_from_bytes(&b)
|
||||
.map_err(|_| Error::bad_database("Invalid joinedcount in db."))
|
||||
})
|
||||
.transpose()?)
|
||||
}
|
||||
|
||||
/// Returns an iterator over all User IDs who ever joined a room.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub fn room_useroncejoined<'a>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue