summary refs log tree commit diff
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-09-16 10:31:59 +0100
committerErik Johnston <erik@matrix.org>2016-09-16 10:31:59 +0100
commitd84319ae1048837c766eb2e56f91eb521aeed4a6 (patch)
tree1cc266b05421c83bb45acd591dc31ccc1d6c5c9e
parentSupport filtering remote room lists (diff)
downloadsynapse-d84319ae1048837c766eb2e56f91eb521aeed4a6.tar.xz
Add remote reoom cache
-rw-r--r--synapse/handlers/room_list.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py
index 09189edb65..ec0a293a37 100644
--- a/synapse/handlers/room_list.py
+++ b/synapse/handlers/room_list.py
@@ -38,6 +38,7 @@ class RoomListHandler(BaseHandler):
     def __init__(self, hs):
         super(RoomListHandler, self).__init__(hs)
         self.response_cache = ResponseCache(hs)
+        self.remote_response_cache = ResponseCache(hs, timeout_ms=30 * 1000)
 
     def get_local_public_room_list(self, limit=None, since_token=None,
                                    search_filter=None):
@@ -286,9 +287,8 @@ class RoomListHandler(BaseHandler):
             limit = None
             since_token = None
 
-        res = yield self.hs.get_replication_layer().get_public_rooms(
+        res = yield self._get_remote_list_cached(
             server_name, limit=limit, since_token=since_token,
-            search_filter=search_filter,
         )
 
         if search_filter:
@@ -300,6 +300,27 @@ class RoomListHandler(BaseHandler):
 
         defer.returnValue(res)
 
+    def _get_remote_list_cached(self, server_name, limit=None, since_token=None,
+                                search_filter=None):
+        repl_layer = self.hs.get_replication_layer()
+        if search_filter:
+            # We can't cache when asking for search
+            return repl_layer.get_public_rooms(
+                server_name, limit=limit, since_token=since_token,
+                search_filter=search_filter,
+            )
+
+        result = self.remote_response_cache.get((server_name, limit, since_token))
+        if not result:
+            result = self.remote_response_cache.set(
+                (server_name, limit, since_token),
+                repl_layer.get_public_rooms(
+                    server_name, limit=limit, since_token=since_token,
+                    search_filter=search_filter,
+                )
+            )
+        return result
+
 
 class RoomListNextBatch(namedtuple("RoomListNextBatch", (
     "stream_ordering",  # stream_ordering of the first public room list