From b11f7b5122061d4908b3328689486bc16dc58445 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 11 Jan 2024 11:52:13 +0000 Subject: Improve DB performance of calculating badge counts for push. (#16756) The crux of the change is to try and make the queries simpler and pull out fewer rows. Before, there were quite a few joins against subqueries, which caused postgres to pull out more rows than necessary. Instead, let's simplify the query and do some of the filtering out in Python instead, letting Postgres do better optimizations now that it doesn't have to deal with joins against subqueries. Review note: this is a complete rewrite of the function, so not sure how useful the diff is. --------- Co-authored-by: Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> --- synapse/push/push_tools.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'synapse/push') diff --git a/synapse/push/push_tools.py b/synapse/push/push_tools.py index 03ce0b4dc6..cce9583fa7 100644 --- a/synapse/push/push_tools.py +++ b/synapse/push/push_tools.py @@ -28,17 +28,11 @@ from synapse.storage.databases.main import DataStore async def get_badge_count(store: DataStore, user_id: str, group_by_room: bool) -> int: invites = await store.get_invited_rooms_for_local_user(user_id) - joins = await store.get_rooms_for_user(user_id) badge = len(invites) room_to_count = await store.get_unread_counts_by_room_for_user(user_id) - for room_id, notify_count in room_to_count.items(): - # room_to_count may include rooms which the user has left, - # ignore those. - if room_id not in joins: - continue - + for _room_id, notify_count in room_to_count.items(): if notify_count == 0: continue -- cgit 1.4.1