mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
MSC3575: remove sticky parameters
This commit is contained in:
parent
991f1e2c0d
commit
64ad940bad
2 changed files with 6 additions and 142 deletions
|
|
@ -67,7 +67,7 @@ pub(crate) async fn sync_events_v4_route(
|
|||
) -> Result<Ra<sync_events::v4::Response>, Ra<UiaaResponse>> {
|
||||
let sender_user = body.sender_user.expect("user is authenticated");
|
||||
let sender_device = body.sender_device.expect("user is authenticated");
|
||||
let mut body = body.body;
|
||||
let body = body.body;
|
||||
// Setup watchers, so if there's no response, we can wait for them
|
||||
let watcher = services().globals.watch(&sender_user, &sender_device);
|
||||
|
||||
|
|
@ -88,10 +88,8 @@ pub(crate) async fn sync_events_v4_route(
|
|||
}
|
||||
}
|
||||
|
||||
// Get sticky parameters from cache
|
||||
let known_rooms = services()
|
||||
.users
|
||||
.update_sync_request_with_cache(connection_key.clone(), &mut body);
|
||||
let known_rooms =
|
||||
services().users.get_rooms_in_connection(connection_key.clone());
|
||||
|
||||
let all_joined_rooms = services()
|
||||
.rooms
|
||||
|
|
@ -405,7 +403,6 @@ pub(crate) async fn sync_events_v4_route(
|
|||
|
||||
for r in body.unsubscribe_rooms {
|
||||
known_subscription_rooms.remove(&r);
|
||||
body.room_subscriptions.remove(&r);
|
||||
}
|
||||
|
||||
if body.conn_id.is_some() {
|
||||
|
|
@ -417,12 +414,6 @@ pub(crate) async fn sync_events_v4_route(
|
|||
);
|
||||
}
|
||||
|
||||
if body.conn_id.is_some() {
|
||||
services()
|
||||
.users
|
||||
.update_sync_subscriptions(connection_key, body.room_subscriptions);
|
||||
}
|
||||
|
||||
let mut rooms = BTreeMap::new();
|
||||
for (
|
||||
room_id,
|
||||
|
|
|
|||
|
|
@ -5,14 +5,7 @@ use std::{
|
|||
};
|
||||
|
||||
use ruma::{
|
||||
api::client::{
|
||||
device::Device,
|
||||
filter::FilterDefinition,
|
||||
sync::sync_events::{
|
||||
self,
|
||||
v4::{ExtensionsConfig, SyncRequestList},
|
||||
},
|
||||
},
|
||||
api::client::{device::Device, filter::FilterDefinition},
|
||||
encryption::{CrossSigningKey, DeviceKeys, OneTimeKey},
|
||||
events::AnyToDeviceEvent,
|
||||
serde::Raw,
|
||||
|
|
@ -28,11 +21,7 @@ pub(crate) use data::Data;
|
|||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct SlidingSyncCache {
|
||||
lists: BTreeMap<String, SyncRequestList>,
|
||||
subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>,
|
||||
// For every room, the roomsince number
|
||||
known_rooms: BTreeMap<String, BTreeMap<OwnedRoomId, u64>>,
|
||||
extensions: ExtensionsConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
|
|
@ -77,136 +66,20 @@ impl Service {
|
|||
self.connections.lock().unwrap().remove(connection_key);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub(crate) fn update_sync_request_with_cache(
|
||||
pub(crate) fn get_rooms_in_connection(
|
||||
&self,
|
||||
connection_key: ConnectionKey,
|
||||
request: &mut sync_events::v4::Request,
|
||||
) -> BTreeMap<String, BTreeMap<OwnedRoomId, u64>> {
|
||||
if connection_key.connection.is_none() {
|
||||
return BTreeMap::new();
|
||||
};
|
||||
|
||||
let cached = self.get_cache_entry(connection_key);
|
||||
let mut cached = cached.lock().unwrap();
|
||||
|
||||
for (list_id, list) in &mut request.lists {
|
||||
if let Some(cached_list) = cached.lists.get(list_id) {
|
||||
if list.sort.is_empty() {
|
||||
list.sort.clone_from(&cached_list.sort);
|
||||
}
|
||||
if list.room_details.required_state.is_empty() {
|
||||
list.room_details
|
||||
.required_state
|
||||
.clone_from(&cached_list.room_details.required_state);
|
||||
}
|
||||
list.room_details.timeline_limit = list
|
||||
.room_details
|
||||
.timeline_limit
|
||||
.or(cached_list.room_details.timeline_limit);
|
||||
list.include_old_rooms = list
|
||||
.include_old_rooms
|
||||
.clone()
|
||||
.or(cached_list.include_old_rooms.clone());
|
||||
match (&mut list.filters, cached_list.filters.clone()) {
|
||||
(Some(list_filters), Some(cached_filters)) => {
|
||||
list_filters.is_dm =
|
||||
list_filters.is_dm.or(cached_filters.is_dm);
|
||||
if list_filters.spaces.is_empty() {
|
||||
list_filters.spaces = cached_filters.spaces;
|
||||
}
|
||||
list_filters.is_encrypted = list_filters
|
||||
.is_encrypted
|
||||
.or(cached_filters.is_encrypted);
|
||||
list_filters.is_invite =
|
||||
list_filters.is_invite.or(cached_filters.is_invite);
|
||||
if list_filters.room_types.is_empty() {
|
||||
list_filters.room_types = cached_filters.room_types;
|
||||
}
|
||||
if list_filters.not_room_types.is_empty() {
|
||||
list_filters.not_room_types =
|
||||
cached_filters.not_room_types;
|
||||
}
|
||||
list_filters.room_name_like = list_filters
|
||||
.room_name_like
|
||||
.clone()
|
||||
.or(cached_filters.room_name_like);
|
||||
if list_filters.tags.is_empty() {
|
||||
list_filters.tags = cached_filters.tags;
|
||||
}
|
||||
if list_filters.not_tags.is_empty() {
|
||||
list_filters.not_tags = cached_filters.not_tags;
|
||||
}
|
||||
}
|
||||
(_, Some(cached_filters)) => {
|
||||
list.filters = Some(cached_filters);
|
||||
}
|
||||
(Some(list_filters), _) => {
|
||||
list.filters = Some(list_filters.clone());
|
||||
}
|
||||
(..) => {}
|
||||
}
|
||||
if list.bump_event_types.is_empty() {
|
||||
list.bump_event_types
|
||||
.clone_from(&cached_list.bump_event_types);
|
||||
}
|
||||
}
|
||||
cached.lists.insert(list_id.clone(), list.clone());
|
||||
}
|
||||
|
||||
cached.subscriptions.extend(
|
||||
request
|
||||
.room_subscriptions
|
||||
.iter()
|
||||
.map(|(k, v)| (k.clone(), v.clone())),
|
||||
);
|
||||
request.room_subscriptions.extend(
|
||||
cached.subscriptions.iter().map(|(k, v)| (k.clone(), v.clone())),
|
||||
);
|
||||
|
||||
request.extensions.e2ee.enabled =
|
||||
request.extensions.e2ee.enabled.or(cached.extensions.e2ee.enabled);
|
||||
|
||||
request.extensions.to_device.enabled = request
|
||||
.extensions
|
||||
.to_device
|
||||
.enabled
|
||||
.or(cached.extensions.to_device.enabled);
|
||||
|
||||
request.extensions.account_data.enabled = request
|
||||
.extensions
|
||||
.account_data
|
||||
.enabled
|
||||
.or(cached.extensions.account_data.enabled);
|
||||
request.extensions.account_data.lists = request
|
||||
.extensions
|
||||
.account_data
|
||||
.lists
|
||||
.clone()
|
||||
.or(cached.extensions.account_data.lists.clone());
|
||||
request.extensions.account_data.rooms = request
|
||||
.extensions
|
||||
.account_data
|
||||
.rooms
|
||||
.clone()
|
||||
.or(cached.extensions.account_data.rooms.clone());
|
||||
|
||||
cached.extensions = request.extensions.clone();
|
||||
let cached = cached.lock().unwrap();
|
||||
|
||||
cached.known_rooms.clone()
|
||||
}
|
||||
|
||||
pub(crate) fn update_sync_subscriptions(
|
||||
&self,
|
||||
connection_key: ConnectionKey,
|
||||
subscriptions: BTreeMap<OwnedRoomId, sync_events::v4::RoomSubscription>,
|
||||
) {
|
||||
let cached = self.get_cache_entry(connection_key);
|
||||
let mut cached = cached.lock().unwrap();
|
||||
|
||||
cached.subscriptions = subscriptions;
|
||||
}
|
||||
|
||||
pub(crate) fn update_sync_known_rooms(
|
||||
&self,
|
||||
connection_key: ConnectionKey,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue