summary refs log tree commit diff
path: root/synapse/handlers/sync.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2023-02-14 12:10:29 +0100
committerGitHub <noreply@github.com>2023-02-14 11:10:29 +0000
commitf09db5c9918b6aaeb1f53ab4fac3a7f05f512c5f (patch)
tree36d2e71312544cd78eb7001cec4921b710c39570 /synapse/handlers/sync.py
parentChange collection[str] to StrCollection in event_auth code (#14929) (diff)
downloadsynapse-f09db5c9918b6aaeb1f53ab4fac3a7f05f512c5f.tar.xz
Skip calculating unread push actions in `/sync` when `enable_push` is false. (#14980)
Diffstat (limited to 'synapse/handlers/sync.py')
-rw-r--r--synapse/handlers/sync.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 4bae46158a..3a9cddf15a 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -269,6 +269,8 @@ class SyncHandler:
         self._state_storage_controller = self._storage_controllers.state
         self._device_handler = hs.get_device_handler()
 
+        self.should_calculate_push_rules = hs.config.push.enable_push
+
         # TODO: flush cache entries on subsequent sync request.
         #    Once we get the next /sync request (ie, one with the same access token
         #    that sets 'since' to 'next_batch'), we know that device won't need a
@@ -1288,6 +1290,12 @@ class SyncHandler:
     async def unread_notifs_for_room_id(
         self, room_id: str, sync_config: SyncConfig
     ) -> RoomNotifCounts:
+        if not self.should_calculate_push_rules:
+            # If push rules have been universally disabled then we know we won't
+            # have any unread counts in the DB, so we may as well skip asking
+            # the DB.
+            return RoomNotifCounts.empty()
+
         with Measure(self.clock, "unread_notifs_for_room_id"):
 
             return await self.store.get_unread_event_push_actions_by_room_for_user(