Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 9cfb3dd

Browse files
committed
Move background update names out to a separate class
`EventsBackgroundUpdatesStore` gets inherited and we don't really want to further pollute the namespace.
1 parent bb472f3 commit 9cfb3dd

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

synapse/storage/databases/main/events_bg_updates.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@
2929
logger = logging.getLogger(__name__)
3030

3131

32+
class _BackgroundUpdates:
33+
EVENT_ORIGIN_SERVER_TS_NAME = "event_origin_server_ts"
34+
EVENT_FIELDS_SENDER_URL_UPDATE_NAME = "event_fields_sender_url"
35+
DELETE_SOFT_FAILED_EXTREMITIES = "delete_soft_failed_extremities"
36+
37+
3238
@attr.s(slots=True, frozen=True)
3339
class _CalculateChainCover:
3440
"""Return value for _calculate_chain_cover_txn."""
@@ -48,19 +54,15 @@ class _CalculateChainCover:
4854

4955

5056
class EventsBackgroundUpdatesStore(SQLBaseStore):
51-
52-
EVENT_ORIGIN_SERVER_TS_NAME = "event_origin_server_ts"
53-
EVENT_FIELDS_SENDER_URL_UPDATE_NAME = "event_fields_sender_url"
54-
DELETE_SOFT_FAILED_EXTREMITIES = "delete_soft_failed_extremities"
55-
5657
def __init__(self, database: DatabasePool, db_conn, hs):
5758
super().__init__(database, db_conn, hs)
5859

5960
self.db_pool.updates.register_background_update_handler(
60-
self.EVENT_ORIGIN_SERVER_TS_NAME, self._background_reindex_origin_server_ts
61+
_BackgroundUpdates.EVENT_ORIGIN_SERVER_TS_NAME,
62+
self._background_reindex_origin_server_ts,
6163
)
6264
self.db_pool.updates.register_background_update_handler(
63-
self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME,
65+
_BackgroundUpdates.EVENT_FIELDS_SENDER_URL_UPDATE_NAME,
6466
self._background_reindex_fields_sender,
6567
)
6668

@@ -85,7 +87,8 @@ def __init__(self, database: DatabasePool, db_conn, hs):
8587
)
8688

8789
self.db_pool.updates.register_background_update_handler(
88-
self.DELETE_SOFT_FAILED_EXTREMITIES, self._cleanup_extremities_bg_update
90+
_BackgroundUpdates.DELETE_SOFT_FAILED_EXTREMITIES,
91+
self._cleanup_extremities_bg_update,
8992
)
9093

9194
self.db_pool.updates.register_background_update_handler(
@@ -190,18 +193,18 @@ def reindex_txn(txn):
190193
}
191194

192195
self.db_pool.updates._background_update_progress_txn(
193-
txn, self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, progress
196+
txn, _BackgroundUpdates.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, progress
194197
)
195198

196199
return len(rows)
197200

198201
result = await self.db_pool.runInteraction(
199-
self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, reindex_txn
202+
_BackgroundUpdates.EVENT_FIELDS_SENDER_URL_UPDATE_NAME, reindex_txn
200203
)
201204

202205
if not result:
203206
await self.db_pool.updates._end_background_update(
204-
self.EVENT_FIELDS_SENDER_URL_UPDATE_NAME
207+
_BackgroundUpdates.EVENT_FIELDS_SENDER_URL_UPDATE_NAME
205208
)
206209

207210
return result
@@ -264,18 +267,18 @@ def reindex_search_txn(txn):
264267
}
265268

266269
self.db_pool.updates._background_update_progress_txn(
267-
txn, self.EVENT_ORIGIN_SERVER_TS_NAME, progress
270+
txn, _BackgroundUpdates.EVENT_ORIGIN_SERVER_TS_NAME, progress
268271
)
269272

270273
return len(rows_to_update)
271274

272275
result = await self.db_pool.runInteraction(
273-
self.EVENT_ORIGIN_SERVER_TS_NAME, reindex_search_txn
276+
_BackgroundUpdates.EVENT_ORIGIN_SERVER_TS_NAME, reindex_search_txn
274277
)
275278

276279
if not result:
277280
await self.db_pool.updates._end_background_update(
278-
self.EVENT_ORIGIN_SERVER_TS_NAME
281+
_BackgroundUpdates.EVENT_ORIGIN_SERVER_TS_NAME
279282
)
280283

281284
return result
@@ -454,7 +457,7 @@ def _cleanup_extremities_bg_update_txn(txn):
454457

455458
if not num_handled:
456459
await self.db_pool.updates._end_background_update(
457-
self.DELETE_SOFT_FAILED_EXTREMITIES
460+
_BackgroundUpdates.DELETE_SOFT_FAILED_EXTREMITIES
458461
)
459462

460463
def _drop_table_txn(txn):

0 commit comments

Comments
 (0)