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

Skip calculating unread push actions in /sync when enable_push is false. #14980

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14980.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Skip calculating unread push actions in /sync when enable_push is false.
5 changes: 5 additions & 0 deletions synapse/handlers/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def __init__(self, hs: "HomeServer"):
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
Expand Down Expand Up @@ -1288,6 +1290,9 @@ async def _find_missing_partial_state_memberships(
async def unread_notifs_for_room_id(
self, room_id: str, sync_config: SyncConfig
) -> RoomNotifCounts:
if not self.should_calculate_push_rules:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment please!

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(
Expand Down
4 changes: 4 additions & 0 deletions synapse/storage/databases/main/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ class RoomNotifCounts:
# Map of thread ID to the notification counts.
threads: Dict[str, NotifCounts]

@staticmethod
def empty() -> "RoomNotifCounts":
return RoomNotifCounts(NotifCounts(), {})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you want this to always return the same instance?


def __len__(self) -> int:
# To properly account for the amount of space in any caches.
return len(self.threads) + 1
Expand Down