29
29
logger = logging .getLogger (__name__ )
30
30
31
31
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
+
32
38
@attr .s (slots = True , frozen = True )
33
39
class _CalculateChainCover :
34
40
"""Return value for _calculate_chain_cover_txn."""
@@ -48,19 +54,15 @@ class _CalculateChainCover:
48
54
49
55
50
56
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
-
56
57
def __init__ (self , database : DatabasePool , db_conn , hs ):
57
58
super ().__init__ (database , db_conn , hs )
58
59
59
60
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 ,
61
63
)
62
64
self .db_pool .updates .register_background_update_handler (
63
- self .EVENT_FIELDS_SENDER_URL_UPDATE_NAME ,
65
+ _BackgroundUpdates .EVENT_FIELDS_SENDER_URL_UPDATE_NAME ,
64
66
self ._background_reindex_fields_sender ,
65
67
)
66
68
@@ -85,7 +87,8 @@ def __init__(self, database: DatabasePool, db_conn, hs):
85
87
)
86
88
87
89
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 ,
89
92
)
90
93
91
94
self .db_pool .updates .register_background_update_handler (
@@ -190,18 +193,18 @@ def reindex_txn(txn):
190
193
}
191
194
192
195
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
194
197
)
195
198
196
199
return len (rows )
197
200
198
201
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
200
203
)
201
204
202
205
if not result :
203
206
await self .db_pool .updates ._end_background_update (
204
- self .EVENT_FIELDS_SENDER_URL_UPDATE_NAME
207
+ _BackgroundUpdates .EVENT_FIELDS_SENDER_URL_UPDATE_NAME
205
208
)
206
209
207
210
return result
@@ -264,18 +267,18 @@ def reindex_search_txn(txn):
264
267
}
265
268
266
269
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
268
271
)
269
272
270
273
return len (rows_to_update )
271
274
272
275
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
274
277
)
275
278
276
279
if not result :
277
280
await self .db_pool .updates ._end_background_update (
278
- self .EVENT_ORIGIN_SERVER_TS_NAME
281
+ _BackgroundUpdates .EVENT_ORIGIN_SERVER_TS_NAME
279
282
)
280
283
281
284
return result
@@ -454,7 +457,7 @@ def _cleanup_extremities_bg_update_txn(txn):
454
457
455
458
if not num_handled :
456
459
await self .db_pool .updates ._end_background_update (
457
- self .DELETE_SOFT_FAILED_EXTREMITIES
460
+ _BackgroundUpdates .DELETE_SOFT_FAILED_EXTREMITIES
458
461
)
459
462
460
463
def _drop_table_txn (txn ):
0 commit comments