Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 74f01e1

Browse files
authored
Skip handling of push actions for outlier events (#10780)
Outlier events don't ever have push actions associated with them, so we can skip some expensive queries during event persistence.
1 parent 0288e60 commit 74f01e1

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

changelog.d/10780.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Minor speed ups when joining large rooms over federation.

synapse/storage/databases/main/events.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -1990,6 +1990,15 @@ def _set_push_actions_for_event_and_users_txn(
19901990
events_and_context.
19911991
"""
19921992

1993+
# Only non outlier events will have push actions associated with them,
1994+
# so let's filter them out. (This makes joining large rooms faster, as
1995+
# these queries took seconds to process all the state events).
1996+
non_outlier_events = [
1997+
event
1998+
for event, _ in events_and_contexts
1999+
if not event.internal_metadata.is_outlier()
2000+
]
2001+
19932002
sql = """
19942003
INSERT INTO event_push_actions (
19952004
room_id, event_id, user_id, actions, stream_ordering,
@@ -2000,7 +2009,7 @@ def _set_push_actions_for_event_and_users_txn(
20002009
WHERE event_id = ?
20012010
"""
20022011

2003-
if events_and_contexts:
2012+
if non_outlier_events:
20042013
txn.execute_batch(
20052014
sql,
20062015
(
@@ -2010,12 +2019,12 @@ def _set_push_actions_for_event_and_users_txn(
20102019
event.depth,
20112020
event.event_id,
20122021
)
2013-
for event, _ in events_and_contexts
2022+
for event in non_outlier_events
20142023
),
20152024
)
20162025

20172026
room_to_event_ids: Dict[str, List[str]] = {}
2018-
for e, _ in events_and_contexts:
2027+
for e in non_outlier_events:
20192028
room_to_event_ids.setdefault(e.room_id, []).append(e.event_id)
20202029

20212030
for room_id, event_ids in room_to_event_ids.items():
@@ -2040,7 +2049,11 @@ def _set_push_actions_for_event_and_users_txn(
20402049
# persisted.
20412050
txn.execute_batch(
20422051
"DELETE FROM event_push_actions_staging WHERE event_id = ?",
2043-
((event.event_id,) for event, _ in all_events_and_contexts),
2052+
(
2053+
(event.event_id,)
2054+
for event, _ in all_events_and_contexts
2055+
if not event.internal_metadata.is_outlier()
2056+
),
20442057
)
20452058

20462059
def _remove_push_actions_for_event_id_txn(self, txn, room_id, event_id):

tests/storage/test_event_push_actions.py

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def _inject_actions(stream, action):
6969
event.room_id = room_id
7070
event.event_id = "$test:example.com"
7171
event.internal_metadata.stream_ordering = stream
72+
event.internal_metadata.is_outlier.return_value = False
7273
event.depth = stream
7374

7475
self.get_success(

0 commit comments

Comments
 (0)