2 files changed, 6 insertions, 0 deletions
diff --git a/changelog.d/16552.misc b/changelog.d/16552.misc
new file mode 100644
index 0000000000..73a0376df0
--- /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 7e992ca4a2..d5fb6ecc73 100644
--- a/synapse/storage/databases/main/event_federation.py
+++ b/synapse/storage/databases/main/event_federation.py
@@ -301,6 +301,11 @@ class EventFederationWorkerStore(SignatureWorkerStore, EventsWorkerStore, SQLBas
# 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
|