summary refs log tree commit diff
path: root/synapse/app/pusher.py
diff options
context:
space:
mode:
authorMark Haines <mark.haines@matrix.org>2016-05-13 17:16:27 +0100
committerMark Haines <mark.haines@matrix.org>2016-05-13 17:16:27 +0100
commitb3f29dc1e59ccb3e53a124d9c0d85d26377350f4 (patch)
tree5f62c041b70409f3fe2b347d5d80debd64261396 /synapse/app/pusher.py
parentUse the SlavedAccountDataStore (diff)
downloadsynapse-b3f29dc1e59ccb3e53a124d9c0d85d26377350f4.tar.xz
Manually expire broken caches like the who_forgot_in_room
Diffstat (limited to 'synapse/app/pusher.py')
-rw-r--r--synapse/app/pusher.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/synapse/app/pusher.py b/synapse/app/pusher.py
index 8ff8329f8e..135dd58c15 100644
--- a/synapse/app/pusher.py
+++ b/synapse/app/pusher.py
@@ -131,6 +131,11 @@ class PusherSlaveStore(
         DataStore.get_profile_displayname.__func__
     )
 
+    # XXX: This is a bit broken because we don't persist forgotten rooms
+    # in a way that they can be streamed. This means that we don't have a
+    # way to invalidate the forgotten rooms cache correctly.
+    # For now we expire the cache every 10 minutes.
+    BROKEN_CACHE_EXPIRY_MS = 60 * 60 * 1000
     who_forgot_in_room = (
         RoomMemberStore.__dict__["who_forgot_in_room"]
     )
@@ -214,6 +219,7 @@ class PusherServer(HomeServer):
         store = self.get_datastore()
         replication_url = self.config.replication_url
         pusher_pool = self.get_pusherpool()
+        clock = self.get_clock()
 
         def stop_pusher(user_id, app_id, pushkey):
             key = "%s:%s" % (app_id, pushkey)
@@ -265,11 +271,21 @@ class PusherServer(HomeServer):
                     min_stream_id, max_stream_id, affected_room_ids
                 )
 
+        def expire_broken_caches():
+            store.who_forgot_in_room.invalidate_all()
+
+        next_expire_broken_caches_ms = 0
         while True:
             try:
                 args = store.stream_positions()
                 args["timeout"] = 30000
                 result = yield http_client.get_json(replication_url, args=args)
+                now_ms = clock.time_msec()
+                if now_ms > next_expire_broken_caches_ms:
+                    expire_broken_caches()
+                    next_expire_broken_caches_ms = (
+                        now_ms + store.BROKEN_CACHE_EXPIRY_MS
+                    )
                 yield store.process_replication(result)
                 poke_pushers(result)
             except: