anonymousland-synapse/synapse
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
..
_scripts Strip trailing / from server_url in register_new_matrix_user (#8823) 2020-11-26 10:57:26 +00:00
api Add type hints to groups code. (#9393) 2021-02-17 08:41:47 -05:00
app Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
appservice Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
config Add a config option to prioritise local users in user directory search results (#9383) 2021-02-19 11:02:03 +00:00
crypto Cache config options in SSL verification (#9255) 2021-01-28 17:38:59 +00:00
events Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
federation Be smarter about which hosts to send presence to when processing room joins (#9402) 2021-02-19 11:37:29 +00:00
groups Add type hints to groups code. (#9393) 2021-02-17 08:41:47 -05:00
handlers Be smarter about which hosts to send presence to when processing room joins (#9402) 2021-02-19 11:37:29 +00:00
http Reduce the memory usage of previewing media files. (#9421) 2021-02-18 09:01:29 -05:00
logging Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
metrics Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
module_api Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
push Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
replication Add configs to make profile data more private (#9203) 2021-02-19 09:50:41 +00:00
res/templates Merge remote-tracking branch 'origin/release-v1.27.0' into social_login_hotfixes 2021-02-03 20:33:32 +00:00
rest Remove deprecated SAML2 callback URL since it does not work. (#9434) 2021-02-18 11:20:33 -05:00
server_notices Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
spam_checker_api Combine SpamCheckerApi with the more generic ModuleApi. (#8464) 2020-10-07 12:03:26 +01:00
state Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
static Add initial support for a "pick your IdP" page (#9017) 2021-01-05 11:25:28 +00:00
storage Add a config option to prioritise local users in user directory search results (#9383) 2021-02-19 11:02:03 +00:00
streams Make token serializing/deserializing async (#8427) 2020-09-30 20:29:19 +01:00
util Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
__init__.py 1.27.0 2021-02-16 13:12:02 +00:00
event_auth.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
notifier.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
python_dependencies.py Add experimental support for PyPy. (#9123) 2021-02-04 08:29:47 -05:00
secrets.py Stop sub-classing object (#8249) 2020-09-04 06:54:56 -04:00
server.py Type hints and validation improvements. (#9321) 2021-02-08 13:59:54 -05:00
types.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
visibility.py Merge pull request #9150 from Yoric/develop-context 2021-02-08 15:53:44 +01:00