summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2022-04-04 20:13:45 +0100
committerErik Johnston <erik@matrix.org>2022-04-04 20:13:45 +0100
commitee5377c9aa938145e5a206ea57a7d326b91becfd (patch)
treee7e2cae9e8748d1aa6bec9aec6be92e63977b7ca
parentMerge remote-tracking branch 'origin/develop' into matrix-org-hotfixes (diff)
parentNewsfile (diff)
downloadsynapse-ee5377c9aa938145e5a206ea57a7d326b91becfd.tar.xz
Merge branch 'erikj/prefill_device_list_change_cache' into matrix-org-hotfixes
-rw-r--r--changelog.d/12367.feature1
-rw-r--r--synapse/replication/slave/storage/devices.py12
-rw-r--r--synapse/storage/databases/main/__init__.py12
3 files changed, 23 insertions, 2 deletions
diff --git a/changelog.d/12367.feature b/changelog.d/12367.feature
new file mode 100644
index 0000000000..34bb60e966
--- /dev/null
+++ b/changelog.d/12367.feature
@@ -0,0 +1 @@
+Reduce overhead of restarting synchrotrons.
diff --git a/synapse/replication/slave/storage/devices.py b/synapse/replication/slave/storage/devices.py
index 0ffd34f1da..a0dd9d2b89 100644
--- a/synapse/replication/slave/storage/devices.py
+++ b/synapse/replication/slave/storage/devices.py
@@ -47,8 +47,18 @@ class SlavedDeviceStore(EndToEndKeyWorkerStore, DeviceWorkerStore, BaseSlavedSto
             ],
         )
         device_list_max = self._device_list_id_gen.get_current_token()
+        device_list_prefill, min_device_list_id = self.db_pool.get_cache_dict(
+            db_conn,
+            "device_lists_stream",
+            entity_column="user_id",
+            stream_column="stream_id",
+            max_value=device_list_max,
+            limit=1000,
+        )
         self._device_list_stream_cache = StreamChangeCache(
-            "DeviceListStreamChangeCache", device_list_max
+            "DeviceListStreamChangeCache",
+            min_device_list_id,
+            prefilled_cache=device_list_prefill,
         )
         self._user_signature_stream_cache = StreamChangeCache(
             "UserSignatureStreamChangeCache", device_list_max
diff --git a/synapse/storage/databases/main/__init__.py b/synapse/storage/databases/main/__init__.py
index f024761ba7..68abf6783f 100644
--- a/synapse/storage/databases/main/__init__.py
+++ b/synapse/storage/databases/main/__init__.py
@@ -183,8 +183,18 @@ class DataStore(
         super().__init__(database, db_conn, hs)
 
         device_list_max = self._device_list_id_gen.get_current_token()
+        device_list_prefill, min_device_list_id = self.db_pool.get_cache_dict(
+            db_conn,
+            "device_lists_stream",
+            entity_column="user_id",
+            stream_column="stream_id",
+            max_value=device_list_max,
+            limit=1000,
+        )
         self._device_list_stream_cache = StreamChangeCache(
-            "DeviceListStreamChangeCache", device_list_max
+            "DeviceListStreamChangeCache",
+            min_device_list_id,
+            prefilled_cache=device_list_prefill,
         )
         self._user_signature_stream_cache = StreamChangeCache(
             "UserSignatureStreamChangeCache", device_list_max