forked-synapse/synapse/handlers
Andrew Morgan 8bcfc2eaad
Be smarter about which hosts to send presence to when processing room joins (#9402)
This PR attempts to eliminate unnecessary presence sending work when your local server joins a room, or when a remote server joins a room your server is participating in by processing state deltas in chunks rather than individually.

---

When your server joins a room for the first time, it requests the historical state as well. This chunk of new state is passed to the presence handler which, after filtering that state down to only membership joins, will send presence updates to homeservers for each join processed.

It turns out that we were being a bit naive and processing each event individually, and sending out presence updates for every one of those joins. Even if many different joins were users on the same server (hello IRC bridges), we'd send presence to that same homeserver for every remote user join we saw.

This PR attempts to deduplicate all of that by processing the entire batch of state deltas at once, instead of only doing each join individually. We process the joins and note down which servers need which presence:

* If it was a local user join, send that user's latest presence to all servers in the room
* If it was a remote user join, send the presence for all local users in the room to that homeserver

We deduplicate by inserting all of those pending updates into a dictionary of the form:

```
{
  server_name1: {presence_update1, ...},
  server_name2: {presence_update1, presence_update2, ...}
}
```

Only after building this dict do we then start sending out presence updates.
2021-02-19 11:37:29 +00:00
..
ui_auth UI Auth via SSO: redirect the user to an appropriate SSO. (#9081) 2021-01-12 17:38:03 +00:00
__init__.py Remove the deprecated Handlers object (#8494) 2020-10-09 07:24:34 -04:00
_base.py Simplify the flow for SSO UIA (#8881) 2020-12-08 14:03:38 +00:00
account_data.py Allow moving account data and receipts streams off master (#9104) 2021-01-18 15:47:59 +00:00
account_validity.py Add type hints for account validity handler (#8620) 2020-10-26 14:17:31 -04:00
acme_issuing_service.py Add type hints to various handlers. (#9223) 2021-01-26 10:50:21 -05:00
acme.py Add type hints to various handlers. (#9223) 2021-01-26 10:50:21 -05:00
admin.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
appservice.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
auth.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
cas_handler.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
deactivate_account.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
device.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
devicemessage.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
directory.py Allow spam-checker modules to be provide async methods. (#8890) 2020-12-11 14:05:15 -05:00
e2e_keys.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
e2e_room_keys.py Add type hints to E2E handler. (#9232) 2021-01-28 08:34:19 -05:00
events.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
federation.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
groups_local.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
identity.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
initial_sync.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
message.py Add configs to make profile data more private (#9203) 2021-02-19 09:50:41 +00:00
oidc_handler.py Support for form_post in OIDC responses (#9376) 2021-02-17 10:15:14 +00:00
pagination.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
password_policy.py Add type hints to some handlers (#8505) 2020-10-09 07:20:51 -04:00
presence.py Be smarter about which hosts to send presence to when processing room joins (#9402) 2021-02-19 11:37:29 +00:00
profile.py Add configs to make profile data more private (#9203) 2021-02-19 09:50:41 +00:00
read_marker.py Allow moving account data and receipts streams off master (#9104) 2021-01-18 15:47:59 +00:00
receipts.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
register.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
room_list.py Add type hints to admin and room list handlers. (#8973) 2020-12-29 17:42:10 -05:00
room_member_worker.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
room_member.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
room.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
saml_handler.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
search.py Add type hints to various handlers. (#9223) 2021-01-26 10:50:21 -05:00
set_password.py Add type hints to various handlers. (#9223) 2021-01-26 10:50:21 -05:00
sso.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
state_deltas.py Add type hints to various handlers. (#9223) 2021-01-26 10:50:21 -05:00
stats.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
sync.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
typing.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
user_directory.py Add back the guard against the user directory stream position not existing. (#9428) 2021-02-18 08:44:19 -05:00