lazy-construct presence; avoids useless db queries in sender and syncer.

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-04-16 02:00:54 -07:00 committed by June
parent 8b003e6be2
commit 33cc3d56c1
5 changed files with 16 additions and 11 deletions

View file

@ -571,7 +571,7 @@ async fn process_presence_updates(
presence_updates: &mut HashMap<OwnedUserId, PresenceEvent>, since: u64, syncing_user: &OwnedUserId,
) -> Result<()> {
// Take presence updates
for (user_id, _, presence_event) in services().presence.presence_since(since) {
for (user_id, _, presence_bytes) in services().presence.presence_since(since) {
if !services()
.rooms
.state_cache
@ -580,6 +580,8 @@ async fn process_presence_updates(
continue;
}
use crate::service::presence::Presence;
let presence_event = Presence::from_json_bytes_to_event(&presence_bytes, &user_id)?;
match presence_updates.entry(user_id) {
Entry::Vacant(slot) => {
slot.insert(presence_event);