From 3a00f13436ae981baa9717dc740ea2e6c3d14f3c Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 21 Jan 2016 14:55:59 +0000 Subject: [PATCH 1/2] Only compute badge count when necessary. This reverts commit d7265977376eb391007cde55c4b2d9b8f54d452b. --- synapse/push/__init__.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/synapse/push/__init__.py b/synapse/push/__init__.py index 9a4af2b3ca..bbfe9b8a50 100644 --- a/synapse/push/__init__.py +++ b/synapse/push/__init__.py @@ -125,9 +125,6 @@ class Pusher(object): from_tok = StreamToken.from_string(self.last_token) config = PaginationConfig(from_token=from_tok, limit='1') timeout = (300 + random.randint(-60, 60)) * 1000 - # note that we need to get read receipts down the stream as we need to - # wake up when one arrives. we don't need to explicitly look for - # them though. chunk = yield self.evStreamHandler.get_stream( self.user_id, config, timeout=timeout, affect_presence=False ) @@ -135,12 +132,23 @@ class Pusher(object): # limiting to 1 may get 1 event plus 1 presence event, so # pick out the actual event single_event = None + read_receipt = None for c in chunk['chunk']: if 'event_id' in c: # Hmmm... single_event = c + elif c['type'] == 'm.receipt': + read_receipt = c + + have_updated_badge = False + if read_receipt: + for receipt_part in read_receipt['content'].values(): + if 'm.read' in receipt_part: + if self.user_id in receipt_part['m.read'].keys(): + have_updated_badge = True if not single_event: - yield self.update_badge() + if have_updated_badge: + yield self.update_badge() self.last_token = chunk['end'] yield self.store.update_pusher_last_token( self.app_id, @@ -185,6 +193,9 @@ class Pusher(object): yield self.hs.get_pusherpool().remove_pusher( self.app_id, pk, self.user_id ) + else: + if have_updated_badge: + yield self.update_badge() processed = True if not self.alive: From 8f66fe639211988f66778d6b8a40a2a5fd2cfaa1 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 21 Jan 2016 15:02:07 +0000 Subject: [PATCH 2/2] Cache get_unread_event_push_actions_by_room_for_user --- synapse/storage/event_push_actions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/synapse/storage/event_push_actions.py b/synapse/storage/event_push_actions.py index 6b7cebc9ce..aa61cf5569 100644 --- a/synapse/storage/event_push_actions.py +++ b/synapse/storage/event_push_actions.py @@ -15,6 +15,7 @@ from ._base import SQLBaseStore from twisted.internet import defer +from synapse.util.caches.descriptors import cachedInlineCallbacks import logging import ujson as json @@ -46,7 +47,7 @@ class EventPushActionsStore(SQLBaseStore): values ) - @defer.inlineCallbacks + @cachedInlineCallbacks(num_args=3) def get_unread_event_push_actions_by_room_for_user( self, room_id, user_id, last_read_event_id ):