Optimize heroes calculation using member state instead of timeline scan.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user