summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-01-29 13:34:48 +0000
committerErik Johnston <erik@matrix.org>2016-01-29 13:34:48 +0000
commitea320d34641f98c7aa477e2340ff265c1ac63419 (patch)
tree602c0e2fd95bf6deb23966d3387cbcf4d8502819 /synapse
parentMerge pull request #536 from matrix-org/erikj/sync (diff)
downloadsynapse-ea320d34641f98c7aa477e2340ff265c1ac63419.tar.xz
Don't work out unread_notifs_for_room_id unless needed
Diffstat (limited to '')
-rw-r--r--synapse/handlers/sync.py23
1 files changed, 12 insertions, 11 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 51ec4702db..075566417f 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -697,17 +697,6 @@ class SyncHandler(BaseHandler):
         if just_joined:
             state = yield self.get_state_at(room_id, now_token)
 
-        notifs = yield self.unread_notifs_for_room_id(
-            room_id, sync_config, all_ephemeral_by_room
-        )
-
-        unread_notifications = {}
-        if notifs is not None:
-            unread_notifications["notification_count"] = len(notifs)
-            unread_notifications["highlight_count"] = len([
-                1 for notif in notifs if _action_has_highlight(notif["actions"])
-            ])
-
         state = {
             (e.type, e.state_key): e
             for e in sync_config.filter_collection.filter_room_state(state.values())
@@ -725,6 +714,7 @@ class SyncHandler(BaseHandler):
             ephemeral_by_room.get(room_id, [])
         )
 
+        unread_notifications = {}
         room_sync = JoinedSyncResult(
             room_id=room_id,
             timeline=batch,
@@ -734,6 +724,17 @@ class SyncHandler(BaseHandler):
             unread_notifications=unread_notifications,
         )
 
+        if room_sync:
+            notifs = yield self.unread_notifs_for_room_id(
+                room_id, sync_config, all_ephemeral_by_room
+            )
+
+            if notifs is not None:
+                unread_notifications["notification_count"] = len(notifs)
+                unread_notifications["highlight_count"] = len([
+                    1 for notif in notifs if _action_has_highlight(notif["actions"])
+                ])
+
         logger.debug("Room sync: %r", room_sync)
 
         defer.returnValue(room_sync)