chain_width to 50

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-04-22 04:42:26 +00:00
parent 9b658d86b2
commit 76509830e6
190 changed files with 3469 additions and 930 deletions

View File

@@ -51,7 +51,11 @@ async fn load_timeline(
// Take the last events for the timeline
pin_mut!(non_timeline_pdus);
let timeline_pdus: Vec<_> = non_timeline_pdus.by_ref().take(limit).collect().await;
let timeline_pdus: Vec<_> = non_timeline_pdus
.by_ref()
.take(limit)
.collect()
.await;
let timeline_pdus: Vec<_> = timeline_pdus.into_iter().rev().collect();

View File

@@ -480,7 +480,10 @@ async fn handle_left_room(
let mut left_state_events = Vec::new();
let since_shortstatehash = services.rooms.user.get_token_shortstatehash(room_id, since);
let since_shortstatehash = services
.rooms
.user
.get_token_shortstatehash(room_id, since);
let since_state_ids: HashMap<_, OwnedEventId> = since_shortstatehash
.map_ok(|since_shortstatehash| {
@@ -640,7 +643,11 @@ async fn load_joined_room(
let (timeline_pdus, limited) = timeline;
let initial = since_shortstatehash.is_none();
let lazy_loading_enabled = filter.room.state.lazy_load_options.is_enabled()
|| filter.room.timeline.lazy_load_options.is_enabled();
|| filter
.room
.timeline
.lazy_load_options
.is_enabled();
let lazy_loading_context = &lazy_loading::Context {
user_id: sender_user,
@@ -652,7 +659,12 @@ async fn load_joined_room(
// Reset lazy loading because this is an initial sync
let lazy_load_reset: OptionFuture<_> = initial
.then(|| services.rooms.lazy_loading.reset(lazy_loading_context))
.then(|| {
services
.rooms
.lazy_loading
.reset(lazy_loading_context)
})
.into();
lazy_load_reset.await;
@@ -964,15 +976,23 @@ async fn calculate_state_initial(
.ready_filter_map(|((event_type, state_key), event_id)| {
let lazy = !full_state
&& event_type == StateEventType::RoomMember
&& state_key.as_str().try_into().is_ok_and(|user_id: &UserId| {
sender_user != user_id
&& witness.is_some_and(|witness| !witness.contains(user_id))
});
&& state_key
.as_str()
.try_into()
.is_ok_and(|user_id: &UserId| {
sender_user != user_id
&& witness.is_some_and(|witness| !witness.contains(user_id))
});
lazy.or_some(event_id)
})
.broad_filter_map(|event_id: OwnedEventId| async move {
services.rooms.timeline.get_pdu(&event_id).await.ok()
services
.rooms
.timeline
.get_pdu(&event_id)
.await
.ok()
})
.collect()
.map(Ok);
@@ -1085,7 +1105,12 @@ async fn calculate_state_incremental<'a>(
.ok()
})
.broad_filter_map(|event_id: OwnedEventId| async move {
services.rooms.timeline.get_pdu(&event_id).await.ok()
services
.rooms
.timeline
.get_pdu(&event_id)
.await
.ok()
})
.collect::<Vec<_>>()
.await;
@@ -1118,7 +1143,9 @@ async fn calculate_state_incremental<'a>(
})
.await;
let send_member_count = state_events.iter().any(|event| event.kind == RoomMember);
let send_member_count = state_events
.iter()
.any(|event| event.kind == RoomMember);
let (joined_member_count, invited_member_count, heroes) = if send_member_count {
calculate_counts(services, room_id, sender_user).await?
@@ -1205,8 +1232,11 @@ async fn fold_hero(
sender_user: &UserId,
pdu: PduEvent,
) -> Vec<OwnedUserId> {
let Some(user_id): Option<&UserId> =
pdu.state_key.as_deref().map(TryInto::try_into).flat_ok()
let Some(user_id): Option<&UserId> = pdu
.state_key
.as_deref()
.map(TryInto::try_into)
.flat_ok()
else {
return heroes;
};
@@ -1229,8 +1259,14 @@ async fn fold_hero(
}
let (is_invited, is_joined) = join(
services.rooms.state_cache.is_invited(user_id, room_id),
services.rooms.state_cache.is_joined(user_id, room_id),
services
.rooms
.state_cache
.is_invited(user_id, room_id),
services
.rooms
.state_cache
.is_joined(user_id, room_id),
)
.await;

View File

@@ -53,8 +53,14 @@ pub(crate) async fn sync_events_v4_route(
body: Ruma<sync_events::v4::Request>,
) -> Result<sync_events::v4::Response> {
debug_assert!(DEFAULT_BUMP_TYPES.is_sorted(), "DEFAULT_BUMP_TYPES is not sorted");
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
let sender_user = body
.sender_user
.as_ref()
.expect("user is authenticated");
let sender_device = body
.sender_device
.as_ref()
.expect("user is authenticated");
let mut body = body.body;
// Setup watchers, so if there's no response, we can wait for them
@@ -80,7 +86,9 @@ pub(crate) async fn sync_events_v4_route(
}
if globalsince == 0 {
services.sync.forget_sync_request_connection(&db_key);
services
.sync
.forget_sync_request_connection(&db_key);
}
// Get sticky parameters from cache
@@ -113,8 +121,14 @@ pub(crate) async fn sync_events_v4_route(
.collect()
.await;
let all_invited_rooms: Vec<&RoomId> = all_invited_rooms.iter().map(AsRef::as_ref).collect();
let all_knocked_rooms: Vec<&RoomId> = all_knocked_rooms.iter().map(AsRef::as_ref).collect();
let all_invited_rooms: Vec<&RoomId> = all_invited_rooms
.iter()
.map(AsRef::as_ref)
.collect();
let all_knocked_rooms: Vec<&RoomId> = all_knocked_rooms
.iter()
.map(AsRef::as_ref)
.collect();
let all_rooms: Vec<&RoomId> = all_joined_rooms
.iter()
@@ -123,8 +137,14 @@ pub(crate) async fn sync_events_v4_route(
.chain(all_knocked_rooms.iter().map(AsRef::as_ref))
.collect();
let all_joined_rooms = all_joined_rooms.iter().map(AsRef::as_ref).collect();
let all_invited_rooms = all_invited_rooms.iter().map(AsRef::as_ref).collect();
let all_joined_rooms = all_joined_rooms
.iter()
.map(AsRef::as_ref)
.collect();
let all_invited_rooms = all_invited_rooms
.iter()
.map(AsRef::as_ref)
.collect();
if body.extensions.to_device.enabled.unwrap_or(false) {
services
@@ -143,7 +163,12 @@ pub(crate) async fn sync_events_v4_route(
global: Vec::new(),
rooms: BTreeMap::new(),
};
if body.extensions.account_data.enabled.unwrap_or(false) {
if body
.extensions
.account_data
.enabled
.unwrap_or(false)
{
account_data.global = services
.account_data
.changes_since(None, sender_user, globalsince, Some(next_batch))
@@ -179,8 +204,11 @@ pub(crate) async fn sync_events_v4_route(
for room_id in &all_joined_rooms {
let room_id: &&RoomId = room_id;
let Ok(current_shortstatehash) =
services.rooms.state.get_room_shortstatehash(room_id).await
let Ok(current_shortstatehash) = services
.rooms
.state
.get_room_shortstatehash(room_id)
.await
else {
error!("Room {room_id} has no state");
continue;
@@ -373,13 +401,16 @@ pub(crate) async fn sync_events_v4_route(
Vec::new()
};
new_known_rooms.extend(room_ids.clone().into_iter().map(ToOwned::to_owned));
new_known_rooms.extend(
room_ids
.clone()
.into_iter()
.map(ToOwned::to_owned),
);
for room_id in &room_ids {
let todo_room = todo_rooms.entry((*room_id).to_owned()).or_insert((
BTreeSet::new(),
0_usize,
u64::MAX,
));
let todo_room = todo_rooms
.entry((*room_id).to_owned())
.or_insert((BTreeSet::new(), 0_usize, u64::MAX));
let limit: usize = list
.room_details
@@ -409,7 +440,10 @@ pub(crate) async fn sync_events_v4_route(
op: SlidingOp::Sync,
range: Some(r),
index: None,
room_ids: room_ids.into_iter().map(ToOwned::to_owned).collect(),
room_ids: room_ids
.into_iter()
.map(ToOwned::to_owned)
.collect(),
room_id: None,
}
})
@@ -575,7 +609,10 @@ pub(crate) async fn sync_events_v4_route(
if roomsince != &0
&& timeline_pdus.is_empty()
&& account_data.rooms.get(room_id).is_some_and(Vec::is_empty)
&& account_data
.rooms
.get(room_id)
.is_some_and(Vec::is_empty)
&& receipt_size == 0
{
continue;
@@ -610,8 +647,9 @@ pub(crate) async fn sync_events_v4_route(
for (_, pdu) in timeline_pdus {
let ts = MilliSecondsSinceUnixEpoch(pdu.origin_server_ts);
if DEFAULT_BUMP_TYPES.binary_search(&pdu.kind).is_ok()
&& timestamp.is_none_or(|time| time <= ts)
if DEFAULT_BUMP_TYPES
.binary_search(&pdu.kind)
.is_ok() && timestamp.is_none_or(|time| time <= ts)
{
timestamp = Some(ts);
}
@@ -658,7 +696,11 @@ pub(crate) async fn sync_events_v4_route(
| Ordering::Greater => {
let firsts = heroes[1..]
.iter()
.map(|h| h.name.clone().unwrap_or_else(|| h.user_id.to_string()))
.map(|h| {
h.name
.clone()
.unwrap_or_else(|| h.user_id.to_string())
})
.collect::<Vec<_>>()
.join(", ");
@@ -694,7 +736,12 @@ pub(crate) async fn sync_events_v4_route(
.or(name),
avatar: match heroes_avatar {
| Some(heroes_avatar) => ruma::JsOption::Some(heroes_avatar),
| _ => match services.rooms.state_accessor.get_avatar(room_id).await {
| _ => match services
.rooms
.state_accessor
.get_avatar(room_id)
.await
{
| ruma::JsOption::Some(avatar) => ruma::JsOption::from_option(avatar.url),
| ruma::JsOption::Null => ruma::JsOption::Null,
| ruma::JsOption::Undefined => ruma::JsOption::Undefined,
@@ -817,9 +864,16 @@ async fn filter_rooms<'a>(
.iter()
.stream()
.filter_map(|r| async move {
let room_type = services.rooms.state_accessor.get_room_type(r).await;
let room_type = services
.rooms
.state_accessor
.get_room_type(r)
.await;
if room_type.as_ref().is_err_and(|e| !e.is_not_found()) {
if room_type
.as_ref()
.is_err_and(|e| !e.is_not_found())
{
return None;
}

View File

@@ -63,8 +63,14 @@ pub(crate) async fn sync_events_v5_route(
body: Ruma<sync_events::v5::Request>,
) -> Result<sync_events::v5::Response> {
debug_assert!(DEFAULT_BUMP_TYPES.is_sorted(), "DEFAULT_BUMP_TYPES is not sorted");
let sender_user = body.sender_user.as_ref().expect("user is authenticated");
let sender_device = body.sender_device.as_ref().expect("user is authenticated");
let sender_user = body
.sender_user
.as_ref()
.expect("user is authenticated");
let sender_device = body
.sender_device
.as_ref()
.expect("user is authenticated");
let mut body = body.body;
// Setup watchers, so if there's no response, we can wait for them
@@ -90,7 +96,9 @@ pub(crate) async fn sync_events_v5_route(
// Client / User requested an initial sync
if globalsince == 0 {
services.sync.forget_snake_sync_connection(&snake_key);
services
.sync
.forget_snake_sync_connection(&snake_key);
}
// Get sticky parameters from cache
@@ -191,7 +199,11 @@ pub(crate) async fn sync_events_v5_route(
if response.rooms.iter().all(|(id, r)| {
r.timeline.is_empty()
&& r.required_state.is_empty()
&& !response.extensions.receipts.rooms.contains_key(id)
&& !response
.extensions
.receipts
.rooms
.contains_key(id)
}) && response
.extensions
.to_device
@@ -322,8 +334,11 @@ where
let room_ids =
active_rooms[usize_from_ruma(range.0)..usize_from_ruma(range.1)].to_vec();
let new_rooms: BTreeSet<OwnedRoomId> =
room_ids.clone().into_iter().map(From::from).collect();
let new_rooms: BTreeSet<OwnedRoomId> = room_ids
.clone()
.into_iter()
.map(From::from)
.collect();
new_known_rooms.extend(new_rooms);
//new_known_rooms.extend(room_ids..cloned());
@@ -394,7 +409,10 @@ where
let mut invite_state = None;
let (timeline_pdus, limited);
let new_room_id: &RoomId = (*room_id).as_ref();
if all_invited_rooms.clone().any(is_equal_to!(new_room_id)) {
if all_invited_rooms
.clone()
.any(is_equal_to!(new_room_id))
{
// TODO: figure out a timestamp we can use for remote invites
invite_state = services
.rooms
@@ -521,8 +539,9 @@ where
for (_, pdu) in timeline_pdus {
let ts = pdu.origin_server_ts;
if DEFAULT_BUMP_TYPES.binary_search(&pdu.kind).is_ok()
&& timestamp.is_none_or(|time| time <= ts)
if DEFAULT_BUMP_TYPES
.binary_search(&pdu.kind)
.is_ok() && timestamp.is_none_or(|time| time <= ts)
{
timestamp = Some(ts);
}
@@ -569,7 +588,11 @@ where
| Ordering::Greater => {
let firsts = heroes[1..]
.iter()
.map(|h| h.name.clone().unwrap_or_else(|| h.user_id.to_string()))
.map(|h| {
h.name
.clone()
.unwrap_or_else(|| h.user_id.to_string())
})
.collect::<Vec<_>>()
.join(", ");
@@ -605,7 +628,12 @@ where
.or(name),
avatar: match heroes_avatar {
| Some(heroes_avatar) => ruma::JsOption::Some(heroes_avatar),
| _ => match services.rooms.state_accessor.get_avatar(room_id).await {
| _ => match services
.rooms
.state_accessor
.get_avatar(room_id)
.await
{
| ruma::JsOption::Some(avatar) => ruma::JsOption::from_option(avatar.url),
| ruma::JsOption::Null => ruma::JsOption::Null,
| ruma::JsOption::Undefined => ruma::JsOption::Undefined,
@@ -674,7 +702,12 @@ async fn collect_account_data(
rooms: BTreeMap::new(),
};
if !body.extensions.account_data.enabled.unwrap_or(false) {
if !body
.extensions
.account_data
.enabled
.unwrap_or(false)
{
return sync_events::v5::response::AccountData::default();
}
@@ -732,8 +765,11 @@ where
);
for room_id in all_joined_rooms {
let Ok(current_shortstatehash) =
services.rooms.state.get_room_shortstatehash(room_id).await
let Ok(current_shortstatehash) = services
.rooms
.state
.get_room_shortstatehash(room_id)
.await
else {
error!("Room {room_id} has no state");
continue;
@@ -934,9 +970,16 @@ where
Rooms: Stream<Item = &'a RoomId> + Send + 'a,
{
rooms.filter_map(async |room_id| {
let room_type = services.rooms.state_accessor.get_room_type(room_id).await;
let room_type = services
.rooms
.state_accessor
.get_room_type(room_id)
.await;
if room_type.as_ref().is_err_and(|e| !e.is_not_found()) {
if room_type
.as_ref()
.is_err_and(|e| !e.is_not_found())
{
return None;
}