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

Commit

Permalink
Concurrently collect room unread counts for push badges (matrix-org#1…
Browse files Browse the repository at this point in the history
…3765)

Most of the time this function is heavily cached, but when that isn't
the case fetching the counts room by room slows down push delivery on
users with many (thousands) of rooms.

Signed off by Nick @ Beeper.
# Conflicts:
#	synapse/push/push_tools.py
  • Loading branch information
Fizzadar committed Sep 15, 2022
1 parent ab301eb commit 15f22f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.d/13765.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Concurrently fetch room push actions when calculating badge counts. Contributed by Nick @ Beeper (@fizzadar).
12 changes: 9 additions & 3 deletions synapse/push/push_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from synapse.push.presentable_names import calculate_room_name, name_from_member_event
from synapse.storage.controllers import StorageControllers
from synapse.storage.databases.main import DataStore
from synapse.util.async_helpers import concurrently_execute


async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -> int:
Expand All @@ -25,14 +26,19 @@ async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -

badge = len(invites)

for room_id in joins:
notifs = await (
store.get_unread_event_push_actions_by_room_for_user(
room_notifs = []

async def get_room_unread_count(room_id: str) -> None:
room_notifs.append(
await store.get_unread_event_push_actions_by_room_for_user(
room_id,
user_id,
)
)

await concurrently_execute(get_room_unread_count, joins, 10)

for notifs in room_notifs:
# Beeper change: Only count a room as having unread messages if we
# have both unread events (MSC2654) *and* notifications (ie, not muted).
if notifs.notify_count == 0 or notifs.unread_count == 0:
Expand Down

0 comments on commit 15f22f0

Please sign in to comment.