mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-07 18:25:00 -04:00
Aggregate unread notif count query for badge count calculation (#14255)
Fetch the unread notification counts used by the badge counts in push notifications for all rooms at once (instead of fetching them per room).
This commit is contained in:
parent
4569eda944
commit
e8bce8999f
4 changed files with 198 additions and 27 deletions
|
@ -156,7 +156,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
|
||||
last_event_id: str
|
||||
|
||||
def _assert_counts(noitf_count: int, highlight_count: int) -> None:
|
||||
def _assert_counts(notif_count: int, highlight_count: int) -> None:
|
||||
counts = self.get_success(
|
||||
self.store.db_pool.runInteraction(
|
||||
"get-unread-counts",
|
||||
|
@ -168,13 +168,22 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
self.assertEqual(
|
||||
counts.main_timeline,
|
||||
NotifCounts(
|
||||
notify_count=noitf_count,
|
||||
notify_count=notif_count,
|
||||
unread_count=0,
|
||||
highlight_count=highlight_count,
|
||||
),
|
||||
)
|
||||
self.assertEqual(counts.threads, {})
|
||||
|
||||
aggregate_counts = self.get_success(
|
||||
self.store.db_pool.runInteraction(
|
||||
"get-aggregate-unread-counts",
|
||||
self.store._get_unread_counts_by_room_for_user_txn,
|
||||
user_id,
|
||||
)
|
||||
)
|
||||
self.assertEqual(aggregate_counts[room_id], notif_count)
|
||||
|
||||
def _create_event(highlight: bool = False) -> str:
|
||||
result = self.helper.send_event(
|
||||
room_id,
|
||||
|
@ -283,7 +292,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
last_event_id: str
|
||||
|
||||
def _assert_counts(
|
||||
noitf_count: int,
|
||||
notif_count: int,
|
||||
highlight_count: int,
|
||||
thread_notif_count: int,
|
||||
thread_highlight_count: int,
|
||||
|
@ -299,7 +308,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
self.assertEqual(
|
||||
counts.main_timeline,
|
||||
NotifCounts(
|
||||
notify_count=noitf_count,
|
||||
notify_count=notif_count,
|
||||
unread_count=0,
|
||||
highlight_count=highlight_count,
|
||||
),
|
||||
|
@ -318,6 +327,17 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
else:
|
||||
self.assertEqual(counts.threads, {})
|
||||
|
||||
aggregate_counts = self.get_success(
|
||||
self.store.db_pool.runInteraction(
|
||||
"get-aggregate-unread-counts",
|
||||
self.store._get_unread_counts_by_room_for_user_txn,
|
||||
user_id,
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
aggregate_counts[room_id], notif_count + thread_notif_count
|
||||
)
|
||||
|
||||
def _create_event(
|
||||
highlight: bool = False, thread_id: Optional[str] = None
|
||||
) -> str:
|
||||
|
@ -454,7 +474,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
last_event_id: str
|
||||
|
||||
def _assert_counts(
|
||||
noitf_count: int,
|
||||
notif_count: int,
|
||||
highlight_count: int,
|
||||
thread_notif_count: int,
|
||||
thread_highlight_count: int,
|
||||
|
@ -470,7 +490,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
self.assertEqual(
|
||||
counts.main_timeline,
|
||||
NotifCounts(
|
||||
notify_count=noitf_count,
|
||||
notify_count=notif_count,
|
||||
unread_count=0,
|
||||
highlight_count=highlight_count,
|
||||
),
|
||||
|
@ -489,6 +509,17 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
else:
|
||||
self.assertEqual(counts.threads, {})
|
||||
|
||||
aggregate_counts = self.get_success(
|
||||
self.store.db_pool.runInteraction(
|
||||
"get-aggregate-unread-counts",
|
||||
self.store._get_unread_counts_by_room_for_user_txn,
|
||||
user_id,
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
aggregate_counts[room_id], notif_count + thread_notif_count
|
||||
)
|
||||
|
||||
def _create_event(
|
||||
highlight: bool = False, thread_id: Optional[str] = None
|
||||
) -> str:
|
||||
|
@ -646,7 +677,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
)
|
||||
return result["event_id"]
|
||||
|
||||
def _assert_counts(noitf_count: int, thread_notif_count: int) -> None:
|
||||
def _assert_counts(notif_count: int, thread_notif_count: int) -> None:
|
||||
counts = self.get_success(
|
||||
self.store.db_pool.runInteraction(
|
||||
"get-unread-counts",
|
||||
|
@ -658,7 +689,7 @@ class EventPushActionsStoreTestCase(HomeserverTestCase):
|
|||
self.assertEqual(
|
||||
counts.main_timeline,
|
||||
NotifCounts(
|
||||
notify_count=noitf_count, unread_count=0, highlight_count=0
|
||||
notify_count=notif_count, unread_count=0, highlight_count=0
|
||||
),
|
||||
)
|
||||
if thread_notif_count:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue