From 460743da16da5df041b135ba607404bc71f29341 Mon Sep 17 00:00:00 2001 From: Jason Little Date: Wed, 22 Nov 2023 04:59:16 -0600 Subject: [PATCH] Filter out auth chain queries that don't exist (#16552) --- changelog.d/16552.misc | 1 + synapse/storage/databases/main/event_federation.py | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 changelog.d/16552.misc diff --git a/changelog.d/16552.misc b/changelog.d/16552.misc new file mode 100644 index 000000000000..73a0376df097 --- /dev/null +++ b/changelog.d/16552.misc @@ -0,0 +1 @@ +Reduce a little database load while processing state auth chains. diff --git a/synapse/storage/databases/main/event_federation.py b/synapse/storage/databases/main/event_federation.py index 7e992ca4a28c..d5fb6ecc73bc 100644 --- a/synapse/storage/databases/main/event_federation.py +++ b/synapse/storage/databases/main/event_federation.py @@ -301,6 +301,11 @@ def _get_auth_chain_ids_using_cover_index_txn( # Add the initial set of chains, excluding the sequence corresponding to # initial event. for chain_id, seq_no in event_chains.items(): + # Check if the initial event is the first item in the chain. If so, then + # there is nothing new to add from this chain. + if seq_no == 1: + continue + chains[chain_id] = max(seq_no - 1, chains.get(chain_id, 0)) # Now for each chain we figure out the maximum sequence number reachable