mirror of
https://mau.dev/maunium/synapse.git
synced 2024-11-15 22:42:23 +01:00
Optimisation for filter_events_for_server
We're better off hashing just the event_id than the whole ((type, state_key), event_id) tuple - so use a dict instead of a set. Also, iteritems > items.
This commit is contained in:
parent
c6dbd216e6
commit
495975e231
2 changed files with 7 additions and 7 deletions
1
changelog.d/4017.misc
Normal file
1
changelog.d/4017.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Optimisation for serving federation requests
|
|
@ -324,14 +324,13 @@ def filter_events_for_server(store, server_name, events):
|
||||||
# server's domain.
|
# server's domain.
|
||||||
#
|
#
|
||||||
# event_to_state_ids contains lots of duplicates, so it turns out to be
|
# event_to_state_ids contains lots of duplicates, so it turns out to be
|
||||||
# cheaper to build a complete set of unique
|
# cheaper to build a complete event_id => (type, state_key) dict, and then
|
||||||
# ((type, state_key), event_id) tuples, and then filter out the ones we
|
# filter out the ones we don't want
|
||||||
# don't want.
|
|
||||||
#
|
#
|
||||||
state_key_to_event_id_set = {
|
event_id_to_state_key = {
|
||||||
e
|
event_id: key
|
||||||
for key_to_eid in itervalues(event_to_state_ids)
|
for key_to_eid in itervalues(event_to_state_ids)
|
||||||
for e in key_to_eid.items()
|
for key, event_id in iteritems(key_to_eid)
|
||||||
}
|
}
|
||||||
|
|
||||||
def include(typ, state_key):
|
def include(typ, state_key):
|
||||||
|
@ -346,7 +345,7 @@ def filter_events_for_server(store, server_name, events):
|
||||||
|
|
||||||
event_map = yield store.get_events([
|
event_map = yield store.get_events([
|
||||||
e_id
|
e_id
|
||||||
for key, e_id in state_key_to_event_id_set
|
for e_id, key in iteritems(event_id_to_state_key)
|
||||||
if include(key[0], key[1])
|
if include(key[0], key[1])
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue