mirror of
https://github.com/element-hq/synapse.git
synced 2026-09-09 22:35:43 +00:00
Faster have_finished_sliding_sync_background_jobs
This commit is contained in:
@@ -44,7 +44,7 @@ from synapse._pydantic_compat import HAS_PYDANTIC_V2
|
||||
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||
from synapse.storage.engines import PostgresEngine
|
||||
from synapse.storage.types import Connection, Cursor
|
||||
from synapse.types import JsonDict
|
||||
from synapse.types import JsonDict, StrCollection
|
||||
from synapse.util import Clock, json_encoder
|
||||
|
||||
from . import engines
|
||||
@@ -487,6 +487,25 @@ class BackgroundUpdater:
|
||||
|
||||
return not update_exists
|
||||
|
||||
async def have_completed_background_updates(
|
||||
self, update_names: StrCollection
|
||||
) -> bool:
|
||||
"""Return the name of background updates that have not yet been
|
||||
completed"""
|
||||
if self._all_done:
|
||||
return True
|
||||
|
||||
rows = await self.db_pool.simple_select_many_batch(
|
||||
table="background_updates",
|
||||
column="update_name",
|
||||
iterable=update_names,
|
||||
retcols=("update_name",),
|
||||
desc="get_uncompleted_background_updates",
|
||||
)
|
||||
|
||||
# If we find any rows then we've not completed the update.
|
||||
return not bool(rows)
|
||||
|
||||
async def do_next_background_update(self, sleep: bool = True) -> bool:
|
||||
"""Does some amount of work on the next queued background update
|
||||
|
||||
|
||||
@@ -2275,16 +2275,11 @@ class EventsBackgroundUpdatesStore(StreamWorkerStore, StateDeltasStore, SQLBaseS
|
||||
async def have_finished_sliding_sync_background_jobs(self) -> bool:
|
||||
"""Return if its safe to use the sliding sync membership tables."""
|
||||
|
||||
# TODO: Find a more efficient way of checking this. A cache?
|
||||
return (
|
||||
await self.db_pool.updates.has_completed_background_update(
|
||||
_BackgroundUpdates.SLIDING_SYNC_PREFILL_JOINED_ROOMS_TO_RECALCULATE_TABLE_BG_UPDATE
|
||||
)
|
||||
or await self.db_pool.updates.has_completed_background_update(
|
||||
_BackgroundUpdates.SLIDING_SYNC_JOINED_ROOMS_BG_UPDATE
|
||||
)
|
||||
or await self.db_pool.updates.has_completed_background_update(
|
||||
_BackgroundUpdates.SLIDING_SYNC_MEMBERSHIP_SNAPSHOTS_BG_UPDATE
|
||||
return await self.db_pool.updates.have_completed_background_updates(
|
||||
(
|
||||
_BackgroundUpdates.SLIDING_SYNC_PREFILL_JOINED_ROOMS_TO_RECALCULATE_TABLE_BG_UPDATE,
|
||||
_BackgroundUpdates.SLIDING_SYNC_JOINED_ROOMS_BG_UPDATE,
|
||||
_BackgroundUpdates.SLIDING_SYNC_MEMBERSHIP_SNAPSHOTS_BG_UPDATE,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user