mirror of
https://github.com/element-hq/synapse.git
synced 2026-08-14 13:40:39 +00:00
Cache 'has_completed_background_updates'
This commit is contained in:
@@ -262,6 +262,10 @@ class BackgroundUpdater:
|
||||
# enum?
|
||||
self._all_done = False
|
||||
|
||||
# A set of background updates that we have queried the database for and
|
||||
# found to be completed.
|
||||
self._completed_background_updates: set[str] = set()
|
||||
|
||||
# Whether we're currently running updates
|
||||
self._running = False
|
||||
|
||||
@@ -394,9 +398,15 @@ class BackgroundUpdater:
|
||||
return perf
|
||||
|
||||
def start_doing_background_updates(self) -> None:
|
||||
"""Start doing background updates in the background.
|
||||
|
||||
This gets called both on startup and when the admin API is used to
|
||||
reschedule background updates.
|
||||
"""
|
||||
if self.enabled:
|
||||
# if we start a new background update, not all updates are done.
|
||||
self._all_done = False
|
||||
self._completed_background_updates.clear()
|
||||
sleep = self.sleep_enabled
|
||||
self.hs.run_as_background_process(
|
||||
"background_updates",
|
||||
@@ -478,6 +488,9 @@ class BackgroundUpdater:
|
||||
if update_name == self._current_background_update:
|
||||
return False
|
||||
|
||||
if update_name in self._completed_background_updates:
|
||||
return True
|
||||
|
||||
update_exists = await self.db_pool.simple_select_one_onecol(
|
||||
"background_updates",
|
||||
keyvalues={"update_name": update_name},
|
||||
@@ -486,6 +499,9 @@ class BackgroundUpdater:
|
||||
allow_none=True,
|
||||
)
|
||||
|
||||
if not update_exists:
|
||||
self._completed_background_updates.add(update_name)
|
||||
|
||||
return not update_exists
|
||||
|
||||
async def have_completed_background_updates(
|
||||
|
||||
Reference in New Issue
Block a user