Optimize heroes calculation using member state instead of timeline scan.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-11-19 02:14:35 +00:00
parent 5147b541b5
commit e60e86e9ed

View File

@@ -1275,28 +1275,23 @@ async fn calculate_heroes(
sender_user: &UserId, sender_user: &UserId,
) -> Vec<OwnedUserId> { ) -> Vec<OwnedUserId> {
services services
.timeline .state_accessor
.all_pdus(sender_user, room_id) .room_state_type_pdus(room_id, &StateEventType::RoomMember)
.ready_filter(|(_, pdu)| pdu.kind == RoomMember) .ready_filter_map(Result::ok)
.fold_default(|heroes: Vec<_>, (_, pdu)| { .fold_default(|heroes: Vec<_>, pdu| {
fold_hero(heroes, services, room_id, sender_user, pdu) fold_hero(heroes, services, room_id, sender_user, pdu)
}) })
.await .await
} }
async fn fold_hero( async fn fold_hero<Pdu: Event>(
mut heroes: Vec<OwnedUserId>, mut heroes: Vec<OwnedUserId>,
services: &Services, services: &Services,
room_id: &RoomId, room_id: &RoomId,
sender_user: &UserId, sender_user: &UserId,
pdu: PduEvent, pdu: Pdu,
) -> Vec<OwnedUserId> { ) -> Vec<OwnedUserId> {
let Some(user_id): Option<&UserId> = pdu let Some(user_id): Option<&UserId> = pdu.state_key().map(TryInto::try_into).flat_ok() else {
.state_key
.as_deref()
.map(TryInto::try_into)
.flat_ok()
else {
return heroes; return heroes;
}; };