summary refs log tree commit diff
path: root/synapse/storage/account_data.py
diff options
context:
space:
mode:
authorErik Johnston <erikj@jki.re>2018-03-01 17:12:34 +0000
committerGitHub <noreply@github.com>2018-03-01 17:12:34 +0000
commit9e08a93a7bc1f7b8e0ab46663ae759490ddcbccf (patch)
treeaa29b5ba7f771c42595ee3a5ed79761e86a8e7ac /synapse/storage/account_data.py
parentMerge pull request #2926 from matrix-org/erikj/member_handler_move (diff)
parentFewer lies are better (diff)
downloadsynapse-9e08a93a7bc1f7b8e0ab46663ae759490ddcbccf.tar.xz
Merge pull request #2927 from matrix-org/erikj/read_marker_caches
Improve caching for read_marker API
Diffstat (limited to 'synapse/storage/account_data.py')
-rw-r--r--synapse/storage/account_data.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/synapse/storage/account_data.py b/synapse/storage/account_data.py
index 466194e96f..e70c9423e3 100644
--- a/synapse/storage/account_data.py
+++ b/synapse/storage/account_data.py
@@ -133,6 +133,7 @@ class AccountDataWorkerStore(SQLBaseStore):
             for row in rows
         })
 
+    @cached(num_args=2)
     def get_account_data_for_room(self, user_id, room_id):
         """Get all the client account_data for a user for a room.
 
@@ -156,6 +157,38 @@ class AccountDataWorkerStore(SQLBaseStore):
             "get_account_data_for_room", get_account_data_for_room_txn
         )
 
+    @cached(num_args=3, max_entries=5000)
+    def get_account_data_for_room_and_type(self, user_id, room_id, account_data_type):
+        """Get the client account_data of given type for a user for a room.
+
+        Args:
+            user_id(str): The user to get the account_data for.
+            room_id(str): The room to get the account_data for.
+            account_data_type (str): The account data type to get.
+        Returns:
+            A deferred of the room account_data for that type, or None if
+            there isn't any set.
+        """
+        def get_account_data_for_room_and_type_txn(txn):
+            content_json = self._simple_select_one_onecol_txn(
+                txn,
+                table="room_account_data",
+                keyvalues={
+                    "user_id": user_id,
+                    "room_id": room_id,
+                    "account_data_type": account_data_type,
+                },
+                retcol="content",
+                allow_none=True
+            )
+
+            return json.loads(content_json) if content_json else None
+
+        return self.runInteraction(
+            "get_account_data_for_room_and_type",
+            get_account_data_for_room_and_type_txn,
+        )
+
     def get_all_updated_account_data(self, last_global_id, last_room_id,
                                      current_id, limit):
         """Get all the client account_data that has changed on the server
@@ -310,6 +343,10 @@ class AccountDataStore(AccountDataWorkerStore):
 
             self._account_data_stream_cache.entity_has_changed(user_id, next_id)
             self.get_account_data_for_user.invalidate((user_id,))
+            self.get_account_data_for_room.invalidate((user_id, room_id,))
+            self.get_account_data_for_room_and_type.prefill(
+                (user_id, room_id, account_data_type,), content,
+            )
 
         result = self._account_data_id_gen.get_current_token()
         defer.returnValue(result)