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

Commit 7f0565e

Browse files
authored
Don't needlessly batch in add_event_to_cache (#10784)
We've already batched up the events previously, and assume in other places in the events.py file that we have. Removing this makes it easier to adjust the batch sizes in one place.
1 parent 273b686 commit 7f0565e

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

changelog.d/10784.misc

Lines changed: 1 addition & 0 deletions
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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,35 +1547,32 @@ def _add_to_cache(self, txn, events_and_contexts):
15471547
to_prefill = []
15481548

15491549
rows = []
1550-
N = 200
1551-
for i in range(0, len(events_and_contexts), N):
1552-
ev_map = {e[0].event_id: e[0] for e in events_and_contexts[i : i + N]}
1553-
if not ev_map:
1554-
break
1555-
1556-
sql = (
1557-
"SELECT "
1558-
" e.event_id as event_id, "
1559-
" r.redacts as redacts,"
1560-
" rej.event_id as rejects "
1561-
" FROM events as e"
1562-
" LEFT JOIN rejections as rej USING (event_id)"
1563-
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
1564-
" WHERE "
1565-
)
15661550

1567-
clause, args = make_in_list_sql_clause(
1568-
self.database_engine, "e.event_id", list(ev_map)
1569-
)
1551+
ev_map = {e.event_id: e for e, _ in events_and_contexts}
1552+
if not ev_map:
1553+
return
15701554

1571-
txn.execute(sql + clause, args)
1572-
rows = self.db_pool.cursor_to_dict(txn)
1573-
for row in rows:
1574-
event = ev_map[row["event_id"]]
1575-
if not row["rejects"] and not row["redacts"]:
1576-
to_prefill.append(
1577-
_EventCacheEntry(event=event, redacted_event=None)
1578-
)
1555+
sql = (
1556+
"SELECT "
1557+
" e.event_id as event_id, "
1558+
" r.redacts as redacts,"
1559+
" rej.event_id as rejects "
1560+
" FROM events as e"
1561+
" LEFT JOIN rejections as rej USING (event_id)"
1562+
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
1563+
" WHERE "
1564+
)
1565+
1566+
clause, args = make_in_list_sql_clause(
1567+
self.database_engine, "e.event_id", list(ev_map)
1568+
)
1569+
1570+
txn.execute(sql + clause, args)
1571+
rows = self.db_pool.cursor_to_dict(txn)
1572+
for row in rows:
1573+
event = ev_map[row["event_id"]]
1574+
if not row["rejects"] and not row["redacts"]:
1575+
to_prefill.append(_EventCacheEntry(event=event, redacted_event=None))
15791576

15801577
def prefill():
15811578
for cache_entry in to_prefill:

0 commit comments

Comments
 (0)