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

Commit 15f22f0

Browse files
committed
Concurrently collect room unread counts for push badges (matrix-org#13765)
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
1 parent ab301eb commit 15f22f0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

changelog.d/13765.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Concurrently fetch room push actions when calculating badge counts. Contributed by Nick @ Beeper (@fizzadar).

synapse/push/push_tools.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from synapse.push.presentable_names import calculate_room_name, name_from_member_event
1818
from synapse.storage.controllers import StorageControllers
1919
from synapse.storage.databases.main import DataStore
20+
from synapse.util.async_helpers import concurrently_execute
2021

2122

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

2627
badge = len(invites)
2728

28-
for room_id in joins:
29-
notifs = await (
30-
store.get_unread_event_push_actions_by_room_for_user(
29+
room_notifs = []
30+
31+
async def get_room_unread_count(room_id: str) -> None:
32+
room_notifs.append(
33+
await store.get_unread_event_push_actions_by_room_for_user(
3134
room_id,
3235
user_id,
3336
)
3437
)
3538

39+
await concurrently_execute(get_room_unread_count, joins, 10)
40+
41+
for notifs in room_notifs:
3642
# Beeper change: Only count a room as having unread messages if we
3743
# have both unread events (MSC2654) *and* notifications (ie, not muted).
3844
if notifs.notify_count == 0 or notifs.unread_count == 0:

0 commit comments

Comments
 (0)