summary refs log tree commit diff
path: root/synapse/storage
diff options
context:
space:
mode:
Diffstat (limited to 'synapse/storage')
-rw-r--r--synapse/storage/account_data.py20
-rw-r--r--synapse/storage/events.py2
-rw-r--r--synapse/storage/receipts.py8
-rw-r--r--synapse/storage/stream.py8
-rw-r--r--synapse/storage/tags.py14
5 files changed, 42 insertions, 10 deletions
diff --git a/synapse/storage/account_data.py b/synapse/storage/account_data.py
index 9c6597e012..95294c3f6c 100644
--- a/synapse/storage/account_data.py
+++ b/synapse/storage/account_data.py
@@ -14,6 +14,7 @@
 # limitations under the License.
 
 from ._base import SQLBaseStore
+from synapse.util.caches.stream_change_cache import StreamChangeCache
 from twisted.internet import defer
 
 import ujson as json
@@ -23,6 +24,13 @@ logger = logging.getLogger(__name__)
 
 
 class AccountDataStore(SQLBaseStore):
+    def __init__(self, hs):
+        super(AccountDataStore, self).__init__(hs)
+
+        self._account_data_stream_cache = StreamChangeCache(
+            "AccountDataChangeCache", self._account_data_id_gen.get_max_token(None),
+            max_size=1000,
+        )
 
     def get_account_data_for_user(self, user_id):
         """Get all the client account_data for a user.
@@ -83,7 +91,7 @@ class AccountDataStore(SQLBaseStore):
             "get_account_data_for_room", get_account_data_for_room_txn
         )
 
-    def get_updated_account_data_for_user(self, user_id, stream_id):
+    def get_updated_account_data_for_user(self, user_id, stream_id, room_ids=None):
         """Get all the client account_data for a that's changed.
 
         Args:
@@ -120,6 +128,12 @@ class AccountDataStore(SQLBaseStore):
 
             return (global_account_data, account_data_by_room)
 
+        changed = self._account_data_stream_cache.get_entity_has_changed(
+            user_id, int(stream_id)
+        )
+        if not changed:
+            defer.returnValue(({}, {}))
+
         return self.runInteraction(
             "get_updated_account_data_for_user", get_updated_account_data_for_user_txn
         )
@@ -186,6 +200,10 @@ class AccountDataStore(SQLBaseStore):
                     "content": content_json,
                 }
             )
+            txn.call_after(
+                self._account_data_stream_cache.entity_has_changed,
+                user_id, next_id,
+            )
             self._update_max_stream_id(txn, next_id)
 
         with (yield self._account_data_id_gen.get_next(self)) as next_id:
diff --git a/synapse/storage/events.py b/synapse/storage/events.py
index 2d2270b297..5e85552029 100644
--- a/synapse/storage/events.py
+++ b/synapse/storage/events.py
@@ -212,7 +212,7 @@ class EventsStore(SQLBaseStore):
 
             if not backfilled:
                 txn.call_after(
-                    self._events_stream_cache.room_has_changed,
+                    self._events_stream_cache.entity_has_changed,
                     event.room_id, event.internal_metadata.stream_ordering,
                 )
 
diff --git a/synapse/storage/receipts.py b/synapse/storage/receipts.py
index 5ffbfdec51..8068c73740 100644
--- a/synapse/storage/receipts.py
+++ b/synapse/storage/receipts.py
@@ -15,7 +15,7 @@
 
 from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cachedInlineCallbacks, cachedList, cached
-from synapse.util.caches.room_change_cache import RoomStreamChangeCache
+from synapse.util.caches.stream_change_cache import StreamChangeCache
 
 from twisted.internet import defer
 
@@ -30,7 +30,7 @@ class ReceiptsStore(SQLBaseStore):
     def __init__(self, hs):
         super(ReceiptsStore, self).__init__(hs)
 
-        self._receipts_stream_cache = RoomStreamChangeCache(
+        self._receipts_stream_cache = StreamChangeCache(
             "ReceiptsRoomChangeCache", self._receipts_id_gen.get_max_token(None)
         )
 
@@ -77,7 +77,7 @@ class ReceiptsStore(SQLBaseStore):
         room_ids = set(room_ids)
 
         if from_key:
-            room_ids = yield self._receipts_stream_cache.get_rooms_changed(
+            room_ids = yield self._receipts_stream_cache.get_entities_changed(
                 room_ids, from_key
             )
 
@@ -222,7 +222,7 @@ class ReceiptsStore(SQLBaseStore):
         txn.call_after(self.get_linearized_receipts_for_room.invalidate_all)
 
         txn.call_after(
-            self._receipts_stream_cache.room_has_changed,
+            self._receipts_stream_cache.entity_has_changed,
             room_id, stream_id
         )
 
diff --git a/synapse/storage/stream.py b/synapse/storage/stream.py
index 6a724193e1..c7d7893328 100644
--- a/synapse/storage/stream.py
+++ b/synapse/storage/stream.py
@@ -37,7 +37,7 @@ from twisted.internet import defer
 
 from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cachedInlineCallbacks
-from synapse.util.caches.room_change_cache import RoomStreamChangeCache
+from synapse.util.caches.stream_change_cache import StreamChangeCache
 from synapse.api.constants import EventTypes
 from synapse.types import RoomStreamToken
 from synapse.util.logutils import log_function
@@ -81,7 +81,7 @@ class StreamStore(SQLBaseStore):
     def __init__(self, hs):
         super(StreamStore, self).__init__(hs)
 
-        self._events_stream_cache = RoomStreamChangeCache(
+        self._events_stream_cache = StreamChangeCache(
             "EventsRoomStreamChangeCache", self._stream_id_gen.get_max_token(None)
         )
 
@@ -168,7 +168,7 @@ class StreamStore(SQLBaseStore):
     def get_room_events_stream_for_rooms(self, room_ids, from_key, to_key, limit=0):
         from_id = RoomStreamToken.parse_stream_token(from_key).stream
 
-        room_ids = yield self._events_stream_cache.get_rooms_changed(
+        room_ids = yield self._events_stream_cache.get_entities_changed(
             room_ids, from_id
         )
 
@@ -200,7 +200,7 @@ class StreamStore(SQLBaseStore):
             defer.returnValue(([], from_key))
 
         if from_id:
-            has_changed = yield self._events_stream_cache.get_room_has_changed(
+            has_changed = yield self._events_stream_cache.get_entity_has_changed(
                 room_id, from_id
             )
 
diff --git a/synapse/storage/tags.py b/synapse/storage/tags.py
index 4c39e07cbd..50af899192 100644
--- a/synapse/storage/tags.py
+++ b/synapse/storage/tags.py
@@ -15,6 +15,7 @@
 
 from ._base import SQLBaseStore
 from synapse.util.caches.descriptors import cached
+from synapse.util.caches.stream_change_cache import StreamChangeCache
 from twisted.internet import defer
 
 import ujson as json
@@ -24,6 +25,13 @@ logger = logging.getLogger(__name__)
 
 
 class TagsStore(SQLBaseStore):
+    def __init__(self, hs):
+        super(TagsStore, self).__init__(hs)
+
+        self._tags_stream_cache = StreamChangeCache(
+            "TagsChangeCache", self._account_data_id_gen.get_max_token(None),
+            max_size=1000,
+        )
 
     def get_max_account_data_stream_id(self):
         """Get the current max stream id for the private user data stream
@@ -80,6 +88,10 @@ class TagsStore(SQLBaseStore):
             room_ids = [row[0] for row in txn.fetchall()]
             return room_ids
 
+        changed = self._tags_stream_cache.get_entity_has_changed(user_id, int(stream_id))
+        if not changed:
+            defer.returnValue({})
+
         room_ids = yield self.runInteraction(
             "get_updated_tags", get_updated_tags_txn
         )
@@ -177,6 +189,8 @@ class TagsStore(SQLBaseStore):
             next_id(int): The the revision to advance to.
         """
 
+        txn.call_after(self._tags_stream_cache.entity_has_changed, user_id, next_id)
+
         update_max_id_sql = (
             "UPDATE account_data_max_stream_id"
             " SET stream_id = ?"