diff options
author | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-12-20 12:57:47 +0000 |
---|---|---|
committer | Olivier Wilkinson (reivilibre) <oliverw@matrix.org> | 2021-12-20 12:57:47 +0000 |
commit | 3ae955ea0bba7fdc852f1a7a24e0af9bcc5233cd (patch) | |
tree | 2f515b973060bec8a84c20d46d8c24522dc2742b | |
parent | Use sorted dicts (diff) | |
download | synapse-3ae955ea0bba7fdc852f1a7a24e0af9bcc5233cd.tar.xz |
Iterate over in-flight requests in descending order
-rw-r--r-- | synapse/storage/databases/state/store.py | 10 |
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 ) |