element-hq / element-hq/synapse
Presence logic for handling newly joined rooms is very inefficient and does duplicate work
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
This issue has been migrated from [#8956](https://github.com/matrix-org/synapse/issues/8956).
---
When a user joins a room Synapse needs to decide what presence updates to send out. For local users joining a room we need to send a presence update to all users in the room, for remote users joining we need to send out all local users presence to the remote user.
This is implemented by streaming the current state delta stream, however when the server joins a federated room for the first time the state delta will include join events for *all* members. This leads to a situation where we correctly process the fact that a local user has joined a room and send out presence updates, and *then* incorrectly process each remote join event as if they're a new user join, leading to a lot of unnecessary work and superfluous presence events being generated and sent over federation.
https://github.com/matrix-org/synapse/blob/6d02eb22dfde9551c515acaf73503e2500e00eaf/synapse/handlers/presence.py#L860-L953
On top of that, we should also only send presence updates when this is the first time a remote server shares a room with the local user.
Contributor guide
Assessment
This issue has not been assessed yet.