summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2021-12-20 12:57:47 +0000
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2021-12-20 12:57:47 +0000
commit3ae955ea0bba7fdc852f1a7a24e0af9bcc5233cd (patch)
tree2f515b973060bec8a84c20d46d8c24522dc2742b
parentUse sorted dicts (diff)
downloadsynapse-3ae955ea0bba7fdc852f1a7a24e0af9bcc5233cd.tar.xz
Iterate over in-flight requests in descending order
-rw-r--r--synapse/storage/databases/state/store.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py
index abd8404b7f..602f3e8233 100644
--- a/synapse/storage/databases/state/store.py
+++ b/synapse/storage/databases/state/store.py
@@ -296,10 +296,12 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
 
         state_filter_left_over = state_filter
         reusable_requests = []
-        for (
-            request_state_filter,
-            request_deferred,
-        ) in inflight_requests.items():
+
+        # Iterate over existing requests in roughly biggest-first order.
+        # reversed(inflight_requests) has an efficient iterator implementation,
+        # but reversed(inflight_requests.items()) does not, sadly.
+        for request_state_filter in reversed(inflight_requests):
+            request_deferred = inflight_requests[request_state_filter]
             new_state_filter_left_over = state_filter_left_over.approx_difference(
                 request_state_filter
             )