From 0ecb870c5bd45cc8b5be8419081c35f6473a40b3 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 3 Sep 2021 15:44:00 +0100 Subject: [PATCH 1/3] Speed up persisting redacted events --- synapse/storage/databases/main/events.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index 40b53274fb3d..b2c21dc2d28b 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -1379,18 +1379,18 @@ def get_internal_metadata(event): # If we're persisting an unredacted event we go and ensure # that we mark any redactions that reference this event as # requiring censoring. - sql = "UPDATE redactions SET have_censored = ? WHERE redacts = ?" - txn.execute_batch( - sql, - ( - ( - False, - event.event_id, - ) - for event, _ in events_and_contexts - if not event.internal_metadata.is_redacted() - ), + unredacted_events = [ + event.event_id + for event, _ in events_and_contexts + if not event.internal_metadata.is_redacted() + ] + sql = "UPDATE redactions SET have_censored = false WHERE " + clause, args = make_in_list_sql_clause( + self.database_engine, + "redacts", + unredacted_events, ) + txn.execute(sql + clause, args) state_events_and_contexts = [ ec for ec in events_and_contexts if ec[0].is_state() From 14908b08b6e11e6e8e511140b0afb6c52beafcb2 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 3 Sep 2021 15:47:40 +0100 Subject: [PATCH 2/3] Newsfile --- changelog.d/10756.misc | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/10756.misc diff --git a/changelog.d/10756.misc b/changelog.d/10756.misc new file mode 100644 index 000000000000..3b7acff03f4f --- /dev/null +++ b/changelog.d/10756.misc @@ -0,0 +1 @@ +Minor speed ups when joining large rooms over federation. From 1e9f130d47b3360bb4a07ec02e18ae0bf9669f1a Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Fri, 3 Sep 2021 16:15:55 +0100 Subject: [PATCH 3/3] Fixup --- synapse/storage/databases/main/events.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/synapse/storage/databases/main/events.py b/synapse/storage/databases/main/events.py index b2c21dc2d28b..1f47caeea633 100644 --- a/synapse/storage/databases/main/events.py +++ b/synapse/storage/databases/main/events.py @@ -1384,13 +1384,13 @@ def get_internal_metadata(event): for event, _ in events_and_contexts if not event.internal_metadata.is_redacted() ] - sql = "UPDATE redactions SET have_censored = false WHERE " + sql = "UPDATE redactions SET have_censored = ? WHERE " clause, args = make_in_list_sql_clause( self.database_engine, "redacts", unredacted_events, ) - txn.execute(sql + clause, args) + txn.execute(sql + clause, [False] + args) state_events_and_contexts = [ ec for ec in events_and_contexts if ec[0].is_state()