2020from twisted .internet import defer
2121
2222from synapse .metrics .background_process_metrics import wrap_as_background_process
23- from synapse .storage import background_updates
23+ from synapse .storage . _base import SQLBaseStore
2424from synapse .util .caches import CACHE_SIZE_FACTOR
2525from synapse .util .caches .descriptors import Cache
2626
3232LAST_SEEN_GRANULARITY = 120 * 1000
3333
3434
35- class ClientIpBackgroundUpdateStore (background_updates . BackgroundUpdateStore ):
35+ class ClientIpBackgroundUpdateStore (SQLBaseStore ):
3636 def __init__ (self , db_conn , hs ):
3737 super (ClientIpBackgroundUpdateStore , self ).__init__ (db_conn , hs )
3838
39- self .register_background_index_update (
39+ self .db . updates . register_background_index_update (
4040 "user_ips_device_index" ,
4141 index_name = "user_ips_device_id" ,
4242 table = "user_ips" ,
4343 columns = ["user_id" , "device_id" , "last_seen" ],
4444 )
4545
46- self .register_background_index_update (
46+ self .db . updates . register_background_index_update (
4747 "user_ips_last_seen_index" ,
4848 index_name = "user_ips_last_seen" ,
4949 table = "user_ips" ,
5050 columns = ["user_id" , "last_seen" ],
5151 )
5252
53- self .register_background_index_update (
53+ self .db . updates . register_background_index_update (
5454 "user_ips_last_seen_only_index" ,
5555 index_name = "user_ips_last_seen_only" ,
5656 table = "user_ips" ,
5757 columns = ["last_seen" ],
5858 )
5959
60- self .register_background_update_handler (
60+ self .db . updates . register_background_update_handler (
6161 "user_ips_analyze" , self ._analyze_user_ip
6262 )
6363
64- self .register_background_update_handler (
64+ self .db . updates . register_background_update_handler (
6565 "user_ips_remove_dupes" , self ._remove_user_ip_dupes
6666 )
6767
6868 # Register a unique index
69- self .register_background_index_update (
69+ self .db . updates . register_background_index_update (
7070 "user_ips_device_unique_index" ,
7171 index_name = "user_ips_user_token_ip_unique_index" ,
7272 table = "user_ips" ,
@@ -75,12 +75,12 @@ def __init__(self, db_conn, hs):
7575 )
7676
7777 # Drop the old non-unique index
78- self .register_background_update_handler (
78+ self .db . updates . register_background_update_handler (
7979 "user_ips_drop_nonunique_index" , self ._remove_user_ip_nonunique
8080 )
8181
8282 # Update the last seen info in devices.
83- self .register_background_update_handler (
83+ self .db . updates . register_background_update_handler (
8484 "devices_last_seen" , self ._devices_last_seen_update
8585 )
8686
@@ -92,7 +92,7 @@ def f(conn):
9292 txn .close ()
9393
9494 yield self .db .runWithConnection (f )
95- yield self ._end_background_update ("user_ips_drop_nonunique_index" )
95+ yield self .db . updates . _end_background_update ("user_ips_drop_nonunique_index" )
9696 return 1
9797
9898 @defer .inlineCallbacks
@@ -108,7 +108,7 @@ def user_ips_analyze(txn):
108108
109109 yield self .db .runInteraction ("user_ips_analyze" , user_ips_analyze )
110110
111- yield self ._end_background_update ("user_ips_analyze" )
111+ yield self .db . updates . _end_background_update ("user_ips_analyze" )
112112
113113 return 1
114114
@@ -271,14 +271,14 @@ def remove(txn):
271271 (user_id , access_token , ip , device_id , user_agent , last_seen ),
272272 )
273273
274- self ._background_update_progress_txn (
274+ self .db . updates . _background_update_progress_txn (
275275 txn , "user_ips_remove_dupes" , {"last_seen" : end_last_seen }
276276 )
277277
278278 yield self .db .runInteraction ("user_ips_dups_remove" , remove )
279279
280280 if last :
281- yield self ._end_background_update ("user_ips_remove_dupes" )
281+ yield self .db . updates . _end_background_update ("user_ips_remove_dupes" )
282282
283283 return batch_size
284284
@@ -344,7 +344,7 @@ def _devices_last_seen_update_txn(txn):
344344 txn .execute_batch (sql , rows )
345345
346346 _ , _ , _ , user_id , device_id = rows [- 1 ]
347- self ._background_update_progress_txn (
347+ self .db . updates . _background_update_progress_txn (
348348 txn ,
349349 "devices_last_seen" ,
350350 {"last_user_id" : user_id , "last_device_id" : device_id },
@@ -357,7 +357,7 @@ def _devices_last_seen_update_txn(txn):
357357 )
358358
359359 if not updated :
360- yield self ._end_background_update ("devices_last_seen" )
360+ yield self .db . updates . _end_background_update ("devices_last_seen" )
361361
362362 return updated
363363
@@ -546,7 +546,9 @@ async def _prune_old_user_ips(self):
546546 # Nothing to do
547547 return
548548
549- if not await self .has_completed_background_update ("devices_last_seen" ):
549+ if not await self .db .updates .has_completed_background_update (
550+ "devices_last_seen"
551+ ):
550552 # Only start pruning if we have finished populating the devices
551553 # last seen info.
552554 return
0 commit comments