MSC3575: make known rooms global per connection rather than per list

This commit is contained in:
Lambda 2025-08-10 19:00:34 +00:00
parent a72ff4f6e6
commit b4f6c88e57
2 changed files with 9 additions and 33 deletions

View file

@ -39,16 +39,15 @@ impl TodoRoom {
&mut self,
required_state: Vec<(StateEventType, String)>,
timeline_limit: UInt,
known_rooms: Option<&BTreeMap<OwnedRoomId, u64>>,
known_rooms: &BTreeMap<OwnedRoomId, u64>,
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,
);

View file

@ -21,7 +21,7 @@ pub(crate) use data::Data;
#[derive(Debug, Default)]
pub(crate) struct SlidingSyncCache {
known_rooms: BTreeMap<String, BTreeMap<OwnedRoomId, u64>>,
known_rooms: BTreeMap<OwnedRoomId, u64>,
}
#[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<String, BTreeMap<OwnedRoomId, u64>> {
) -> BTreeMap<OwnedRoomId, u64> {
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<OwnedRoomId>,
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);
}
}