Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #506 from matrix-org/erikj/push_fast
Browse files Browse the repository at this point in the history
Only compute unread notifications for rooms we send down stream
  • Loading branch information
erikjohnston committed Jan 19, 2016
2 parents 892ee47 + ac2842f commit af30140
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 30 deletions.
50 changes: 22 additions & 28 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = []

Expand Down Expand Up @@ -294,11 +293,10 @@ def full_state_sync_for_joined_room(self, room_id, sync_config,
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"])
])

Expand All @@ -312,8 +310,7 @@ def full_state_sync_for_joined_room(self, room_id, sync_config,
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):
Expand Down Expand Up @@ -533,18 +530,6 @@ def incremental_sync_with_gap(self, sync_config, since_token):
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",
Expand All @@ -565,12 +550,23 @@ def incremental_sync_with_gap(self, sync_config, since_token):
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:
Expand Down Expand Up @@ -708,11 +704,10 @@ def incremental_sync_with_gap_for_room(self, room_id, sync_config,
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"])
])

Expand All @@ -724,8 +719,7 @@ def incremental_sync_with_gap_for_room(self, room_id, sync_config,
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)
Expand Down
3 changes: 1 addition & 2 deletions synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,7 @@ def serialize(event):
if joined:
ephemeral_events = filter.filter_room_ephemeral(room.ephemeral)
result["ephemeral"] = {"events": ephemeral_events}
result["unread_notification_count"] = room.unread_notification_count
result["unread_highlight_count"] = room.unread_highlight_count
result["unread_notifications"] = room.unread_notifications

return result

Expand Down

0 comments on commit af30140

Please sign in to comment.