summary refs log tree commit diff
path: root/synapse/handlers/sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-01-19 17:31:10 +0000
committerErik Johnston <erik@matrix.org>2016-01-19 17:31:10 +0000
commitaf301406216339cc48bcd9481fb7810690048e1f (patch)
treed1382cf2c9055e4c7ea3bb5e29d0e14f60798ee6 /synapse/handlers/sync.py
parentDon't use form of get_state_for_events with None state_key (diff)
parentOnly compute unread notifications for rooms we send down stream (diff)
downloadsynapse-af301406216339cc48bcd9481fb7810690048e1f.tar.xz
Merge pull request #506 from matrix-org/erikj/push_fast
Only compute unread notifications for rooms we send down stream
Diffstat (limited to 'synapse/handlers/sync.py')
-rw-r--r--synapse/handlers/sync.py50
1 files changed, 22 insertions, 28 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index d2864977b0..aca200c1e7 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -54,8 +54,7 @@ class JoinedSyncResult(collections.namedtuple("JoinedSyncResult", [
     "state",             # dict[(str, str), FrozenEvent]
     "ephemeral",
     "account_data",
-    "unread_notification_count",
-    "unread_highlight_count",
+    "unread_notifications",
 ])):
     __slots__ = []
 
@@ -294,11 +293,10 @@ class SyncHandler(BaseHandler):
             room_id, sync_config, ephemeral_by_room
         )
 
-        notif_count = None
-        highlight_count = None
+        unread_notifications = {}
         if notifs is not None:
-            notif_count = len(notifs)
-            highlight_count = len([
+            unread_notifications["notification_count"] = len(notifs)
+            unread_notifications["highlight_count"] = len([
                 1 for notif in notifs if _action_has_highlight(notif["actions"])
             ])
 
@@ -312,8 +310,7 @@ class SyncHandler(BaseHandler):
             account_data=self.account_data_for_room(
                 room_id, tags_by_room, account_data_by_room
             ),
-            unread_notification_count=notif_count,
-            unread_highlight_count=highlight_count,
+            unread_notifications=unread_notifications,
         ))
 
     def account_data_for_user(self, account_data):
@@ -533,18 +530,6 @@ class SyncHandler(BaseHandler):
                 else:
                     prev_batch = now_token
 
-                notifs = yield self.unread_notifs_for_room_id(
-                    room_id, sync_config, all_ephemeral_by_room
-                )
-
-                notif_count = None
-                highlight_count = None
-                if notifs is not None:
-                    notif_count = len(notifs)
-                    highlight_count = len([
-                        1 for notif in notifs if _action_has_highlight(notif["actions"])
-                    ])
-
                 just_joined = yield self.check_joined_room(sync_config, state)
                 if just_joined:
                     logger.debug("User has just joined %s: needs full state",
@@ -565,12 +550,23 @@ class SyncHandler(BaseHandler):
                     account_data=self.account_data_for_room(
                         room_id, tags_by_room, account_data_by_room
                     ),
-                    unread_notification_count=notif_count,
-                    unread_highlight_count=highlight_count,
+                    unread_notifications={},
                 )
                 logger.debug("Result for room %s: %r", room_id, room_sync)
 
                 if room_sync:
+                    notifs = yield self.unread_notifs_for_room_id(
+                        room_id, sync_config, all_ephemeral_by_room
+                    )
+
+                    if notifs is not None:
+                        notif_dict = room_sync.unread_notifications
+                        notif_dict["notification_count"] = len(notifs)
+                        notif_dict["highlight_count"] = len([
+                            1 for notif in notifs
+                            if _action_has_highlight(notif["actions"])
+                        ])
+
                     joined.append(room_sync)
 
         else:
@@ -708,11 +704,10 @@ class SyncHandler(BaseHandler):
             room_id, sync_config, all_ephemeral_by_room
         )
 
-        notif_count = None
-        highlight_count = None
+        unread_notifications = {}
         if notifs is not None:
-            notif_count = len(notifs)
-            highlight_count = len([
+            unread_notifications["notification_count"] = len(notifs)
+            unread_notifications["highlight_count"] = len([
                 1 for notif in notifs if _action_has_highlight(notif["actions"])
             ])
 
@@ -724,8 +719,7 @@ class SyncHandler(BaseHandler):
             account_data=self.account_data_for_room(
                 room_id, tags_by_room, account_data_by_room
             ),
-            unread_notification_count=notif_count,
-            unread_highlight_count=highlight_count,
+            unread_notifications=unread_notifications,
         )
 
         logger.debug("Room sync: %r", room_sync)