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

Commit 4c69a50

Browse files
erikjohnstonjaywink
authored andcommitted
Skip calculating unread push actions in /sync when enable_push is false. (#14980)
1 parent 3e90dfd commit 4c69a50

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

changelog.d/14980.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Skip calculating unread push actions in /sync when enable_push is false.

synapse/handlers/sync.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,8 @@ def __init__(self, hs: "HomeServer"):
269269
self._state_storage_controller = self._storage_controllers.state
270270
self._device_handler = hs.get_device_handler()
271271

272+
self.should_calculate_push_rules = hs.config.push.enable_push
273+
272274
# TODO: flush cache entries on subsequent sync request.
273275
# Once we get the next /sync request (ie, one with the same access token
274276
# that sets 'since' to 'next_batch'), we know that device won't need a
@@ -1288,6 +1290,12 @@ async def _find_missing_partial_state_memberships(
12881290
async def unread_notifs_for_room_id(
12891291
self, room_id: str, sync_config: SyncConfig
12901292
) -> RoomNotifCounts:
1293+
if not self.should_calculate_push_rules:
1294+
# If push rules have been universally disabled then we know we won't
1295+
# have any unread counts in the DB, so we may as well skip asking
1296+
# the DB.
1297+
return RoomNotifCounts.empty()
1298+
12911299
with Measure(self.clock, "unread_notifs_for_room_id"):
12921300

12931301
return await self.store.get_unread_event_push_actions_by_room_for_user(

synapse/storage/databases/main/event_push_actions.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,18 @@ class RoomNotifCounts:
203203
# Map of thread ID to the notification counts.
204204
threads: Dict[str, NotifCounts]
205205

206+
@staticmethod
207+
def empty() -> "RoomNotifCounts":
208+
return _EMPTY_ROOM_NOTIF_COUNTS
209+
206210
def __len__(self) -> int:
207211
# To properly account for the amount of space in any caches.
208212
return len(self.threads) + 1
209213

210214

215+
_EMPTY_ROOM_NOTIF_COUNTS = RoomNotifCounts(NotifCounts(), {})
216+
217+
211218
def _serialize_action(
212219
actions: Collection[Union[Mapping, str]], is_highlight: bool
213220
) -> str:

0 commit comments

Comments
 (0)