diff options
author | Erik Johnston <erik@matrix.org> | 2021-09-10 10:16:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 10:16:52 +0100 |
commit | 7f0565e029791e336933806522d0e87bce870f64 (patch) | |
tree | 2ddc4e2bc18ee18f11b667a19298b4a03a3ab812 | |
parent | Remove unstable MSC2858 API, including `experimental.msc2858_enabled` config ... (diff) | |
download | synapse-7f0565e029791e336933806522d0e87bce870f64.tar.xz |
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.
-rw-r--r-- | changelog.d/10784.misc | 1 | ||||
-rw-r--r-- | synapse/storage/databases/main/events.py | 51 |
2 files changed, 25 insertions, 27 deletions
diff --git a/changelog.d/10784.misc b/changelog.d/10784.misc new file mode 100644 index 0000000000..3b7acff03f --- /dev/null +++ b/changelog.d/10784.misc @@ -0,0 +1 @@ +Minor speed ups when joining large rooms over federation. diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index 14ada8a8b3..8e691678e5 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -1547,35 +1547,32 @@ class PersistEventsStore: to_prefill = [] 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 = ( - "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 " - ) - clause, args = make_in_list_sql_clause( - self.database_engine, "e.event_id", list(ev_map) - ) + ev_map = {e.event_id: e for e, _ in events_and_contexts} + if not ev_map: + return - txn.execute(sql + clause, args) - rows = self.db_pool.cursor_to_dict(txn) - 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) - ) + sql = ( + "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 " + ) + + clause, args = make_in_list_sql_clause( + self.database_engine, "e.event_id", list(ev_map) + ) + + txn.execute(sql + clause, args) + rows = self.db_pool.cursor_to_dict(txn) + 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(): for cache_entry in to_prefill: |