This repository was archived by the owner on Apr 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change
1
+ Skip calculating unread push actions in /sync when enable_push is false.
Original file line number Diff line number Diff line change @@ -269,6 +269,8 @@ def __init__(self, hs: "HomeServer"):
269
269
self ._state_storage_controller = self ._storage_controllers .state
270
270
self ._device_handler = hs .get_device_handler ()
271
271
272
+ self .should_calculate_push_rules = hs .config .push .enable_push
273
+
272
274
# TODO: flush cache entries on subsequent sync request.
273
275
# Once we get the next /sync request (ie, one with the same access token
274
276
# that sets 'since' to 'next_batch'), we know that device won't need a
@@ -1288,6 +1290,12 @@ async def _find_missing_partial_state_memberships(
1288
1290
async def unread_notifs_for_room_id (
1289
1291
self , room_id : str , sync_config : SyncConfig
1290
1292
) -> RoomNotifCounts :
1293
+ if not self .should_calculate_push_rules :
1294
+ # If push rules have been universally disabled then we know we won't
1295
+ # have any unread counts in the DB, so we may as well skip asking
1296
+ # the DB.
1297
+ return RoomNotifCounts .empty ()
1298
+
1291
1299
with Measure (self .clock , "unread_notifs_for_room_id" ):
1292
1300
1293
1301
return await self .store .get_unread_event_push_actions_by_room_for_user (
Original file line number Diff line number Diff line change @@ -203,11 +203,18 @@ class RoomNotifCounts:
203
203
# Map of thread ID to the notification counts.
204
204
threads : Dict [str , NotifCounts ]
205
205
206
+ @staticmethod
207
+ def empty () -> "RoomNotifCounts" :
208
+ return _EMPTY_ROOM_NOTIF_COUNTS
209
+
206
210
def __len__ (self ) -> int :
207
211
# To properly account for the amount of space in any caches.
208
212
return len (self .threads ) + 1
209
213
210
214
215
+ _EMPTY_ROOM_NOTIF_COUNTS = RoomNotifCounts (NotifCounts (), {})
216
+
217
+
211
218
def _serialize_action (
212
219
actions : Collection [Union [Mapping , str ]], is_highlight : bool
213
220
) -> str :
You can’t perform that action at this time.
0 commit comments