@@ -367,6 +367,12 @@ def get_chain_id_txn(txn: Cursor) -> int:
367
367
replaces_index = "event_txn_id_device_id_txn_id" ,
368
368
)
369
369
370
+ self ._has_finished_sliding_sync_background_jobs = False
371
+ """
372
+ Flag to track when the sliding sync background jobs have
373
+ finished (so we don't have to keep querying it every time)
374
+ """
375
+
370
376
def get_un_partial_stated_events_token (self , instance_name : str ) -> int :
371
377
return (
372
378
self ._un_partial_stated_events_stream_id_gen .get_current_token_for_writer (
@@ -2658,13 +2664,19 @@ def _get_events_by_user_in_room_txn(
2658
2664
async def have_finished_sliding_sync_background_jobs (self ) -> bool :
2659
2665
"""Return if it's safe to use the sliding sync membership tables."""
2660
2666
2661
- return await self .db_pool .updates .have_completed_background_updates (
2667
+ if self ._has_finished_sliding_sync_background_jobs :
2668
+ # as an optimisation, once the job finishes, don't issue another
2669
+ # database transaction to check it, since it won't 'un-finish'
2670
+ return True
2671
+
2672
+ self ._has_finished_sliding_sync_background_jobs = await self .db_pool .updates .have_completed_background_updates (
2662
2673
(
2663
2674
_BackgroundUpdates .SLIDING_SYNC_PREFILL_JOINED_ROOMS_TO_RECALCULATE_TABLE_BG_UPDATE ,
2664
2675
_BackgroundUpdates .SLIDING_SYNC_JOINED_ROOMS_BG_UPDATE ,
2665
2676
_BackgroundUpdates .SLIDING_SYNC_MEMBERSHIP_SNAPSHOTS_BG_UPDATE ,
2666
2677
)
2667
2678
)
2679
+ return self ._has_finished_sliding_sync_background_jobs
2668
2680
2669
2681
async def get_sent_invite_count_by_user (self , user_id : str , from_ts : int ) -> int :
2670
2682
"""
0 commit comments