mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 11:06:07 -04:00
Move background update handling out of store
This commit is contained in:
parent
8863624f78
commit
4a33a6dd19
27 changed files with 281 additions and 200 deletions
|
@ -22,7 +22,6 @@ from twisted.internet import defer
|
|||
from synapse.metrics.background_process_metrics import run_as_background_process
|
||||
|
||||
from . import engines
|
||||
from ._base import SQLBaseStore
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
@ -74,7 +73,7 @@ class BackgroundUpdatePerformance(object):
|
|||
return float(self.total_item_count) / float(self.total_duration_ms)
|
||||
|
||||
|
||||
class BackgroundUpdateStore(SQLBaseStore):
|
||||
class BackgroundUpdater(object):
|
||||
""" Background updates are updates to the database that run in the
|
||||
background. Each update processes a batch of data at once. We attempt to
|
||||
limit the impact of each update by monitoring how long each batch takes to
|
||||
|
@ -86,8 +85,10 @@ class BackgroundUpdateStore(SQLBaseStore):
|
|||
BACKGROUND_UPDATE_INTERVAL_MS = 1000
|
||||
BACKGROUND_UPDATE_DURATION_MS = 100
|
||||
|
||||
def __init__(self, db_conn, hs):
|
||||
super(BackgroundUpdateStore, self).__init__(db_conn, hs)
|
||||
def __init__(self, hs, database):
|
||||
self._clock = hs.get_clock()
|
||||
self.db = database
|
||||
|
||||
self._background_update_performance = {}
|
||||
self._background_update_queue = []
|
||||
self._background_update_handlers = {}
|
||||
|
@ -101,9 +102,7 @@ class BackgroundUpdateStore(SQLBaseStore):
|
|||
logger.info("Starting background schema updates")
|
||||
while True:
|
||||
if sleep:
|
||||
yield self.hs.get_clock().sleep(
|
||||
self.BACKGROUND_UPDATE_INTERVAL_MS / 1000.0
|
||||
)
|
||||
yield self._clock.sleep(self.BACKGROUND_UPDATE_INTERVAL_MS / 1000.0)
|
||||
|
||||
try:
|
||||
result = yield self.do_next_background_update(
|
||||
|
@ -380,7 +379,7 @@ class BackgroundUpdateStore(SQLBaseStore):
|
|||
logger.debug("[SQL] %s", sql)
|
||||
c.execute(sql)
|
||||
|
||||
if isinstance(self.database_engine, engines.PostgresEngine):
|
||||
if isinstance(self.db.database_engine, engines.PostgresEngine):
|
||||
runner = create_index_psql
|
||||
elif psql_only:
|
||||
runner = None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue