Skip to content

feat(event cache): process room updates concurrently #5426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions crates/matrix-sdk/src/event_cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ use matrix_sdk_base::{
use matrix_sdk_common::executor::{spawn, JoinHandle};
use room::RoomEventCacheState;
use ruma::{events::AnySyncEphemeralRoomEvent, serde::Raw, OwnedEventId, OwnedRoomId, RoomId};
use tokio::sync::{
broadcast::{channel, error::RecvError, Receiver, Sender},
mpsc, Mutex, RwLock,
use tokio::{
join,
sync::{
broadcast::{channel, error::RecvError, Receiver, Sender},
mpsc, Mutex, RwLock,
},
};
use tracing::{debug, error, info, info_span, instrument, trace, warn, Instrument as _, Span};

Expand Down Expand Up @@ -519,28 +522,37 @@ impl EventCacheInner {
self.multiple_room_updates_lock.lock().await
};

let mut left_futures = Vec::with_capacity(updates.left.len());
let mut joined_futures = Vec::with_capacity(updates.joined.len());

// Left rooms.
for (room_id, left_room_update) in updates.left {
let room = self.for_room(&room_id).await?;
left_futures.push(async move {
trace!(?room_id, "Handling a `LeftRoomUpdate`");

if let Err(err) = room.inner.handle_left_room_update(left_room_update).await {
// Non-fatal error, try to continue to the next room.
error!("handling left room update: {err}");
}
if let Err(err) = room.inner.handle_left_room_update(left_room_update).await {
// Non-fatal error, try to continue to the next room.
error!("handling left room update: {err}");
}
});
}

// Joined rooms.
for (room_id, joined_room_update) in updates.joined {
trace!(?room_id, "Handling a `JoinedRoomUpdate`");

let room = self.for_room(&room_id).await?;
joined_futures.push(async move {
trace!(?room_id, "Handling a `JoinedRoomUpdate`");

if let Err(err) = room.inner.handle_joined_room_update(joined_room_update).await {
// Non-fatal error, try to continue to the next room.
error!(%room_id, "handling joined room update: {err}");
}
if let Err(err) = room.inner.handle_joined_room_update(joined_room_update).await {
// Non-fatal error, try to continue to the next room.
error!(%room_id, "handling joined room update: {err}");
}
});
}

join!(join_all(left_futures), join_all(joined_futures));

// Invited rooms.
// TODO: we don't anything with `updates.invite` at this point.

Expand Down
Loading