diff --git a/src/api/client_server/sync/msc3575.rs b/src/api/client_server/sync/msc3575.rs index 918d9f27..47e93472 100644 --- a/src/api/client_server/sync/msc3575.rs +++ b/src/api/client_server/sync/msc3575.rs @@ -39,16 +39,15 @@ impl TodoRoom { &mut self, required_state: Vec<(StateEventType, String)>, timeline_limit: UInt, - known_rooms: Option<&BTreeMap>, + known_rooms: &BTreeMap, room_id: &RoomId, ) { self.required_state_request.extend(required_state); self.timeline_limit = self.timeline_limit.max(u64::from(timeline_limit).min(100)); // 0 means unknown because it got out of date - self.roomsince = self.roomsince.min( - known_rooms.and_then(|k| k.get(room_id)).copied().unwrap_or(0), - ); + self.roomsince = + self.roomsince.min(known_rooms.get(room_id).copied().unwrap_or(0)); } } impl Default for TodoRoom { @@ -362,7 +361,7 @@ pub(crate) async fn sync_events_v4_route( todo_rooms.entry(room_id.clone()).or_default().update( list.room_details.required_state.clone(), list.room_details.timeline_limit.unwrap_or(uint!(10)), - known_rooms.get(&list_id), + &known_rooms, room_id, ); } @@ -375,16 +374,8 @@ pub(crate) async fn sync_events_v4_route( .unwrap_or(UInt::MAX), }, ); - - services().users.update_sync_known_rooms( - connection_key.clone(), - list_id, - list_room_ids, - globalsince, - ); } - let mut known_subscription_rooms = BTreeSet::new(); for (room_id, room) in &body.room_subscriptions { if !services().rooms.metadata.exists(room_id)? { continue; @@ -392,20 +383,14 @@ pub(crate) async fn sync_events_v4_route( todo_rooms.entry(room_id.clone()).or_default().update( room.required_state.clone(), room.timeline_limit.unwrap_or(uint!(10)), - known_rooms.get("subscriptions"), + &known_rooms, room_id, ); - known_subscription_rooms.insert(room_id.clone()); - } - - for r in body.unsubscribe_rooms { - known_subscription_rooms.remove(&r); } services().users.update_sync_known_rooms( connection_key.clone(), - "subscriptions".to_owned(), - known_subscription_rooms, + todo_rooms.keys().cloned().collect(), globalsince, ); diff --git a/src/service/users.rs b/src/service/users.rs index ab64130e..928843ae 100644 --- a/src/service/users.rs +++ b/src/service/users.rs @@ -21,7 +21,7 @@ pub(crate) use data::Data; #[derive(Debug, Default)] pub(crate) struct SlidingSyncCache { - known_rooms: BTreeMap>, + known_rooms: BTreeMap, } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] @@ -69,7 +69,7 @@ impl Service { pub(crate) fn get_rooms_in_connection( &self, connection_key: ConnectionKey, - ) -> BTreeMap> { + ) -> BTreeMap { let cached = self.get_cache_entry(connection_key); let cached = cached.lock().unwrap(); @@ -79,23 +79,14 @@ impl Service { pub(crate) fn update_sync_known_rooms( &self, connection_key: ConnectionKey, - list_id: String, new_cached_rooms: BTreeSet, globalsince: u64, ) { let cached = self.get_cache_entry(connection_key); let mut cached = cached.lock().unwrap(); - for (roomid, lastsince) in - cached.known_rooms.entry(list_id.clone()).or_default().iter_mut() - { - if !new_cached_rooms.contains(roomid) { - *lastsince = 0; - } - } - let list = cached.known_rooms.entry(list_id).or_default(); for roomid in new_cached_rooms { - list.insert(roomid, globalsince); + cached.known_rooms.insert(roomid, globalsince); } }