fix: Use prepare_lazily_loaded_members for joined rooms

Also, don't take read receipts into consideration for lazy loading.
Synapse doesn't do this and they're making initial syncs very large.
This commit is contained in:
Ginger
2025-10-28 11:32:12 -04:00
parent 3e6571a2b8
commit 693e327004
2 changed files with 16 additions and 36 deletions
+3 -25
View File
@@ -13,7 +13,7 @@ use conduwuit::{
stream::{Tools, WidebandExt}, stream::{Tools, WidebandExt},
}, },
}; };
use conduwuit_service::{Services, rooms::lazy_loading::MemberSet}; use conduwuit_service::Services;
use futures::{ use futures::{
FutureExt, StreamExt, TryFutureExt, FutureExt, StreamExt, TryFutureExt,
future::{OptionFuture, join, join3, join4, try_join}, future::{OptionFuture, join, join3, join4, try_join},
@@ -37,7 +37,7 @@ use super::{load_timeline, share_encrypted_room};
use crate::client::{ use crate::client::{
ignored_filter, ignored_filter,
sync::v3::{ sync::v3::{
DeviceListUpdates, SyncContext, DeviceListUpdates, SyncContext, prepare_lazily_loaded_members,
state::{calculate_state_incremental, calculate_state_initial}, state::{calculate_state_incremental, calculate_state_initial},
}, },
}; };
@@ -199,32 +199,10 @@ pub(super) async fn load_joined_room(
|content: RoomMemberEventContent| content.membership != MembershipState::Join, |content: RoomMemberEventContent| content.membership != MembershipState::Join,
); );
let lazy_loading_context = &sync_context.lazy_loading_context(room_id);
// the user IDs of members whose membership needs to be sent to the client, if // the user IDs of members whose membership needs to be sent to the client, if
// lazy-loading is enabled. // lazy-loading is enabled.
let lazily_loaded_members = let lazily_loaded_members =
OptionFuture::from(sync_context.lazy_loading_enabled().then(|| { prepare_lazily_loaded_members(services, sync_context, room_id, timeline.senders()).await;
let timeline_and_receipt_members: MemberSet = timeline
.senders()
.chain(receipt_events.keys().map(Into::into))
.collect();
services
.rooms
.lazy_loading
.retain_lazy_members(timeline_and_receipt_members, lazy_loading_context)
}))
.await;
// reset lazy loading state on initial sync
if previous_sync_end_count.is_none() {
services
.rooms
.lazy_loading
.reset(lazy_loading_context)
.await;
}
/* /*
compute the state delta between the previous sync and this sync. if this is an initial sync compute the state delta between the previous sync and this sync. if this is an initial sync
+13 -11
View File
@@ -430,8 +430,19 @@ async fn prepare_lazily_loaded_members(
) -> Option<MemberSet> { ) -> Option<MemberSet> {
let lazy_loading_context = &sync_context.lazy_loading_context(room_id); let lazy_loading_context = &sync_context.lazy_loading_context(room_id);
// the user IDs of members whose membership needs to be sent to the client, if // reset lazy loading state on initial sync.
// lazy-loading is enabled. // do this even if lazy loading is disabled so future lazy loads
// will have the correct members.
if sync_context.since.is_none() {
services
.rooms
.lazy_loading
.reset(lazy_loading_context)
.await;
}
// filter the input members through `retain_lazy_members`, which
// contains the actual lazy loading logic.
let lazily_loaded_members = let lazily_loaded_members =
OptionFuture::from(sync_context.lazy_loading_enabled().then(|| { OptionFuture::from(sync_context.lazy_loading_enabled().then(|| {
services services
@@ -441,14 +452,5 @@ async fn prepare_lazily_loaded_members(
})) }))
.await; .await;
// reset lazy loading state on initial sync
if sync_context.since.is_none() {
services
.rooms
.lazy_loading
.reset(lazy_loading_context)
.await;
}
lazily_loaded_members lazily_loaded_members
} }