anonymousland-synapse/synapse/storage/databases/main
Richard van der Hoff af2248f8bf
Optimise missing prev_event handling (#9601)
Background: When we receive incoming federation traffic, and notice that we are missing prev_events from 
the incoming traffic, first we do a `/get_missing_events` request, and then if we still have missing prev_events,
we set up new backwards-extremities. To do that, we need to make a `/state_ids` request to ask the remote
server for the state at those prev_events, and then we may need to then ask the remote server for any events
in that state which we don't already have, as well as the auth events for those missing state events, so that we
can auth them.

This PR attempts to optimise the processing of that state request. The `state_ids` API returns a list of the state
events, as well as a list of all the auth events for *all* of those state events. The optimisation comes from the
observation that we are currently loading all of those auth events into memory at the start of the operation, but
we almost certainly aren't going to need *all* of the auth events. Rather, we can check that we have them, and
leave the actual load into memory for later. (Ideally the federation API would tell us which auth events we're
actually going to need, but it doesn't.)

The effect of this is to reduce the number of events that I need to load for an event in Matrix HQ from about
60000 to about 22000, which means it can stay in my in-memory cache, whereas previously the sheer number
of events meant that all 60K events had to be loaded from db for each request, due to the amount of cache
churn. (NB I've already tripled the size of the cache from its default of 10K).

Unfortunately I've ended up basically C&Ping `_get_state_for_room` and `_get_events_from_store_or_dest` into
a new method, because `_get_state_for_room` is also called during backfill, which expects the auth events to be
returned, so the same tricks don't work. That said, I don't really know why that codepath is completely different
(ultimately we're doing the same thing in setting up a new backwards extremity) so I've left a TODO suggesting
that we clean it up.
2021-03-15 13:51:02 +00:00
..
schema Add a background task to purge unused chain IDs. (#9542) 2021-03-09 11:22:25 -05:00
__init__.py Add type hints to user admin API. (#9521) 2021-03-03 08:09:39 -05:00
account_data.py Fix receipts or account data not being sent down sync (#9193) 2021-01-21 15:09:09 +00:00
appservice.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
cache.py Separate get_current_token into two. (#8113) 2020-08-19 10:39:31 +01:00
censor_events.py Remove frozendict_json_encoder and support frozendicts everywhere 2020-10-28 15:56:57 +00:00
client_ips.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
deviceinbox.py Fix some typos. 2021-02-12 11:14:12 -05:00
devices.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
directory.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
e2e_room_keys.py Convert additional database code to async/await. (#8195) 2020-08-28 07:54:27 -04:00
end_to_end_keys.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
event_federation.py Use the chain cover index in get_auth_chain_ids. (#9576) 2021-03-10 09:57:59 -05:00
event_push_actions.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
events_bg_updates.py Fix a bug in the background task for purging chain cover. (#9583) 2021-03-10 08:55:52 -05:00
events_forward_extremities.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
events_worker.py Optimise missing prev_event handling (#9601) 2021-03-15 13:51:02 +00:00
events.py Refactor to ensure we call check_consistency (#9470) 2021-02-24 10:13:53 +00:00
filtering.py Convert additional databases to async/await part 2 (#8200) 2020-09-01 08:39:04 -04:00
group_server.py Add type hints to groups code. (#9393) 2021-02-17 08:41:47 -05:00
keys.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
media_repository.py Add type hints to user admin API. (#9521) 2021-03-03 08:09:39 -05:00
metrics.py Fix some typos. 2021-02-12 11:14:12 -05:00
monthly_active_users.py Move additional tasks to the background worker, part 3 (#8489) 2020-10-09 07:37:51 -04:00
openid.py Convert additional databases to async/await part 2 (#8200) 2020-09-01 08:39:04 -04:00
presence.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
profile.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
purge_events.py Add a background task to purge unused chain IDs. (#9542) 2021-03-09 11:22:25 -05:00
push_rule.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
pusher.py Make deleting stale pushers a background update (#9536) 2021-03-03 12:08:16 +00:00
receipts.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
registration.py Convert Requester to attrs (#9586) 2021-03-10 18:15:56 +00:00
rejections.py Convert simple_select_one and simple_select_one_onecol to async (#8162) 2020-08-26 07:19:32 -04:00
relations.py Convert additional databases to async/await (#8199) 2020-09-01 09:21:48 -04:00
room.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
roommember.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
signatures.py Convert additional databases to async/await part 2 (#8200) 2020-09-01 08:39:04 -04:00
state_deltas.py Fix some typos. 2021-02-12 11:14:12 -05:00
state.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
stats.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
stream.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
tags.py Allow moving account data and receipts streams off master (#9104) 2021-01-18 15:47:59 +00:00
transactions.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
ui_auth.py Update black, and run auto formatting over the codebase (#9381) 2021-02-16 22:32:34 +00:00
user_directory.py Remove cache for get_shared_rooms_for_users (#9416) 2021-02-22 16:52:45 +00:00
user_erasure_store.py Fixed a bug with reactivating users with the admin API (#8362) 2020-09-22 18:19:01 +01:00