mirror of
https://mau.dev/maunium/synapse.git
synced 2024-12-15 09:03:51 +01:00
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.
This commit is contained in:
parent
273b6861f2
commit
7f0565e029
2 changed files with 24 additions and 26 deletions
1
changelog.d/10784.misc
Normal file
1
changelog.d/10784.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Minor speed ups when joining large rooms over federation.
|
|
@ -1547,35 +1547,32 @@ class PersistEventsStore:
|
||||||
to_prefill = []
|
to_prefill = []
|
||||||
|
|
||||||
rows = []
|
rows = []
|
||||||
N = 200
|
|
||||||
for i in range(0, len(events_and_contexts), N):
|
|
||||||
ev_map = {e[0].event_id: e[0] for e in events_and_contexts[i : i + N]}
|
|
||||||
if not ev_map:
|
|
||||||
break
|
|
||||||
|
|
||||||
sql = (
|
ev_map = {e.event_id: e for e, _ in events_and_contexts}
|
||||||
"SELECT "
|
if not ev_map:
|
||||||
" e.event_id as event_id, "
|
return
|
||||||
" r.redacts as redacts,"
|
|
||||||
" rej.event_id as rejects "
|
|
||||||
" FROM events as e"
|
|
||||||
" LEFT JOIN rejections as rej USING (event_id)"
|
|
||||||
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
|
|
||||||
" WHERE "
|
|
||||||
)
|
|
||||||
|
|
||||||
clause, args = make_in_list_sql_clause(
|
sql = (
|
||||||
self.database_engine, "e.event_id", list(ev_map)
|
"SELECT "
|
||||||
)
|
" e.event_id as event_id, "
|
||||||
|
" r.redacts as redacts,"
|
||||||
|
" rej.event_id as rejects "
|
||||||
|
" FROM events as e"
|
||||||
|
" LEFT JOIN rejections as rej USING (event_id)"
|
||||||
|
" LEFT JOIN redactions as r ON e.event_id = r.redacts"
|
||||||
|
" WHERE "
|
||||||
|
)
|
||||||
|
|
||||||
txn.execute(sql + clause, args)
|
clause, args = make_in_list_sql_clause(
|
||||||
rows = self.db_pool.cursor_to_dict(txn)
|
self.database_engine, "e.event_id", list(ev_map)
|
||||||
for row in rows:
|
)
|
||||||
event = ev_map[row["event_id"]]
|
|
||||||
if not row["rejects"] and not row["redacts"]:
|
txn.execute(sql + clause, args)
|
||||||
to_prefill.append(
|
rows = self.db_pool.cursor_to_dict(txn)
|
||||||
_EventCacheEntry(event=event, redacted_event=None)
|
for row in rows:
|
||||||
)
|
event = ev_map[row["event_id"]]
|
||||||
|
if not row["rejects"] and not row["redacts"]:
|
||||||
|
to_prefill.append(_EventCacheEntry(event=event, redacted_event=None))
|
||||||
|
|
||||||
def prefill():
|
def prefill():
|
||||||
for cache_entry in to_prefill:
|
for cache_entry in to_prefill:
|
||||||
|
|
Loading…
Reference in a new issue