diff options
author | Erik Johnston <erik@matrix.org> | 2023-02-14 12:10:29 +0100 |
---|---|---|
committer | Jason Robinson <jasonr@element.io> | 2023-02-15 12:01:21 +0200 |
commit | 4c69a5026cd783e6b5f4f4ee977159f81b1300d4 (patch) | |
tree | 83a16c1cc875e605f807744ef7b7dd33606412e4 | |
parent | 1.77.0 (diff) | |
download | synapse-github/jaywink/release-v1.77-f09db5c9918b6aaeb1f53ab4fac3a7f05f512c5f.tar.xz |
Skip calculating unread push actions in `/sync` when `enable_push` is false. (#14980) github/jaywink/release-v1.77-f09db5c9918b6aaeb1f53ab4fac3a7f05f512c5f jaywink/release-v1.77-f09db5c9918b6aaeb1f53ab4fac3a7f05f512c5f
-rw-r--r-- | changelog.d/14980.misc | 1 | ||||
-rw-r--r-- | synapse/handlers/sync.py | 8 | ||||
-rw-r--r-- | synapse/storage/databases/main/event_push_actions.py | 7 |
3 files changed, 16 insertions, 0 deletions
diff --git a/changelog.d/14980.misc b/changelog.d/14980.misc new file mode 100644 index 0000000000..145f4a788b --- /dev/null +++ b/changelog.d/14980.misc @@ -0,0 +1 @@ +Skip calculating unread push actions in /sync when enable_push is false. diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py index 3566537894..e56e01b4dc 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( diff --git a/synapse/storage/databases/main/event_push_actions.py b/synapse/storage/databases/main/event_push_actions.py index 3a0c370fde..eeccf5db24 100644 --- a/synapse/storage/databases/main/event_push_actions.py +++ b/synapse/storage/databases/main/event_push_actions.py @@ -203,11 +203,18 @@ class RoomNotifCounts: # Map of thread ID to the notification counts. threads: Dict[str, NotifCounts] + @staticmethod + def empty() -> "RoomNotifCounts": + return _EMPTY_ROOM_NOTIF_COUNTS + def __len__(self) -> int: # To properly account for the amount of space in any caches. return len(self.threads) + 1 +_EMPTY_ROOM_NOTIF_COUNTS = RoomNotifCounts(NotifCounts(), {}) + + def _serialize_action( actions: Collection[Union[Mapping, str]], is_highlight: bool ) -> str: |