summary refs log tree commit diff
diff options
context:
space:
mode:
authorOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2021-12-20 12:55:44 +0000
committerOlivier Wilkinson (reivilibre) <oliverw@matrix.org>2021-12-20 12:55:44 +0000
commitd9800c3f6fc1ecd70d449ec70693f77255e028f7 (patch)
tree717b58f7e7954c7fa3bbc5dd2239f23a2a07e506
parentDefine a comparator for StateFilters (diff)
downloadsynapse-d9800c3f6fc1ecd70d449ec70693f77255e028f7.tar.xz
Use sorted dicts
Note that they are sorted in ascending size order, so this needs further touch-ups.
-rw-r--r--synapse/storage/databases/state/store.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/synapse/storage/databases/state/store.py b/synapse/storage/databases/state/store.py
index 6b665cdbba..abd8404b7f 100644
--- a/synapse/storage/databases/state/store.py
+++ b/synapse/storage/databases/state/store.py
@@ -25,6 +25,7 @@ from typing import (
 )
 
 import attr
+from sortedcontainers import SortedDict
 
 from twisted.internet import defer
 
@@ -143,7 +144,7 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
         # Current ongoing get_state_for_groups in-flight requests
         # {group ID -> {StateFilter -> ObservableDeferred}}
         self._state_group_inflight_requests: Dict[
-            int, Dict[StateFilter, ObservableDeferred[StateMap[str]]]
+            int, SortedDict[StateFilter, ObservableDeferred[StateMap[str]]]
         ] = {}
 
         def get_max_state_group_txn(txn: Cursor) -> int:
@@ -371,7 +372,9 @@ class StateGroupDataStore(StateBackgroundUpdateStore, SQLBaseStore):
         observable_deferred = ObservableDeferred(request_deferred)
 
         # Insert the ObservableDeferred into the cache
-        group_request_dict = self._state_group_inflight_requests.setdefault(group, {})
+        group_request_dict = self._state_group_inflight_requests.setdefault(
+            group, SortedDict(state_filter_rough_size_comparator)
+        )
         group_request_dict[db_state_filter] = observable_deferred
 
         return await make_deferred_yieldable(observable_deferred.observe())