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

Commit e24ff8e

Browse files
authored
Remove HomeServer.get_datastore() (#12031)
The presence of this method was confusing, and mostly present for backwards compatibility. Let's get rid of it. Part of #11733
1 parent c1ac2a8 commit e24ff8e

File tree

230 files changed

+526
-500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+526
-500
lines changed

changelog.d/12031.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove legacy `HomeServer.get_datastore()`.

docs/manhole.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ As a simple example, retrieving an event from the database:
9494

9595
```pycon
9696
>>> from twisted.internet import defer
97-
>>> defer.ensureDeferred(hs.get_datastore().get_event('$1416420717069yeQaw:matrix.org'))
97+
>>> defer.ensureDeferred(hs.get_datastores().main.get_event('$1416420717069yeQaw:matrix.org'))
9898
<Deferred at 0x7ff253fc6998 current result: <FrozenEvent event_id='$1416420717069yeQaw:matrix.org', type='m.room.create', state_key=''>>
9999
```

scripts/update_synapse_database

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class MockHomeserver(HomeServer):
4444

4545

4646
def run_background_updates(hs):
47-
store = hs.get_datastore()
47+
store = hs.get_datastores().main
4848

4949
async def run_background_updates():
5050
await store.db_pool.updates.run_background_updates(sleep=False)

synapse/api/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class Auth:
6060
def __init__(self, hs: "HomeServer"):
6161
self.hs = hs
6262
self.clock = hs.get_clock()
63-
self.store = hs.get_datastore()
63+
self.store = hs.get_datastores().main
6464
self.state = hs.get_state_handler()
6565
self._account_validity_handler = hs.get_account_validity_handler()
6666

synapse/api/auth_blocking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
class AuthBlocking:
3030
def __init__(self, hs: "HomeServer"):
31-
self.store = hs.get_datastore()
31+
self.store = hs.get_datastores().main
3232

3333
self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
3434
self._hs_disabled = hs.config.server.hs_disabled

synapse/api/filtering.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def matrix_user_id_validator(user_id_str: str) -> UserID:
150150
class Filtering:
151151
def __init__(self, hs: "HomeServer"):
152152
self._hs = hs
153-
self.store = hs.get_datastore()
153+
self.store = hs.get_datastores().main
154154

155155
self.DEFAULT_FILTER_COLLECTION = FilterCollection(hs, {})
156156

@@ -294,7 +294,7 @@ def blocks_all_room_timeline(self) -> bool:
294294
class Filter:
295295
def __init__(self, hs: "HomeServer", filter_json: JsonDict):
296296
self._hs = hs
297-
self._store = hs.get_datastore()
297+
self._store = hs.get_datastores().main
298298
self.filter_json = filter_json
299299

300300
self.limit = filter_json.get("limit", 10)

synapse/app/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ def run_sighup(*args: Any, **kwargs: Any) -> None:
448448

449449
# It is now safe to start your Synapse.
450450
hs.start_listening()
451-
hs.get_datastore().db_pool.start_profiling()
451+
hs.get_datastores().main.db_pool.start_profiling()
452452
hs.get_pusherpool().start()
453453

454454
# Log when we start the shut down process.

synapse/app/generic_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self, hs: HomeServer):
142142
"""
143143
super().__init__()
144144
self.auth = hs.get_auth()
145-
self.store = hs.get_datastore()
145+
self.store = hs.get_datastores().main
146146
self.http_client = hs.get_simple_http_client()
147147
self.main_uri = hs.config.worker.worker_main_http_uri
148148

synapse/app/homeserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ async def start() -> None:
372372

373373
await _base.start(hs)
374374

375-
hs.get_datastore().db_pool.updates.start_doing_background_updates()
375+
hs.get_datastores().main.db_pool.updates.start_doing_background_updates()
376376

377377
register_start(start)
378378

synapse/app/phone_stats_home.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async def phone_stats_home(
8282
# General statistics
8383
#
8484

85-
store = hs.get_datastore()
85+
store = hs.get_datastores().main
8686

8787
stats["homeserver"] = hs.config.server.server_name
8888
stats["server_context"] = hs.config.server.server_context
@@ -170,18 +170,22 @@ def performance_stats_init() -> None:
170170
# Rather than update on per session basis, batch up the requests.
171171
# If you increase the loop period, the accuracy of user_daily_visits
172172
# table will decrease
173-
clock.looping_call(hs.get_datastore().generate_user_daily_visits, 5 * 60 * 1000)
173+
clock.looping_call(
174+
hs.get_datastores().main.generate_user_daily_visits, 5 * 60 * 1000
175+
)
174176

175177
# monthly active user limiting functionality
176-
clock.looping_call(hs.get_datastore().reap_monthly_active_users, 1000 * 60 * 60)
177-
hs.get_datastore().reap_monthly_active_users()
178+
clock.looping_call(
179+
hs.get_datastores().main.reap_monthly_active_users, 1000 * 60 * 60
180+
)
181+
hs.get_datastores().main.reap_monthly_active_users()
178182

179183
@wrap_as_background_process("generate_monthly_active_users")
180184
async def generate_monthly_active_users() -> None:
181185
current_mau_count = 0
182186
current_mau_count_by_service = {}
183187
reserved_users: Sized = ()
184-
store = hs.get_datastore()
188+
store = hs.get_datastores().main
185189
if hs.config.server.limit_usage_by_mau or hs.config.server.mau_stats_only:
186190
current_mau_count = await store.get_monthly_active_count()
187191
current_mau_count_by_service = (

synapse/appservice/scheduler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class ApplicationServiceScheduler:
9292

9393
def __init__(self, hs: "HomeServer"):
9494
self.clock = hs.get_clock()
95-
self.store = hs.get_datastore()
95+
self.store = hs.get_datastores().main
9696
self.as_api = hs.get_application_service_api()
9797

9898
self.txn_ctrl = _TransactionController(self.clock, self.store, self.as_api)

synapse/crypto/keyring.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ class StoreKeyFetcher(KeyFetcher):
476476
def __init__(self, hs: "HomeServer"):
477477
super().__init__(hs)
478478

479-
self.store = hs.get_datastore()
479+
self.store = hs.get_datastores().main
480480

481481
async def _fetch_keys(
482482
self, keys_to_fetch: List[_FetchKeyRequest]
@@ -498,7 +498,7 @@ class BaseV2KeyFetcher(KeyFetcher):
498498
def __init__(self, hs: "HomeServer"):
499499
super().__init__(hs)
500500

501-
self.store = hs.get_datastore()
501+
self.store = hs.get_datastores().main
502502
self.config = hs.config
503503

504504
async def process_v2_response(

synapse/events/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def __init__(self, hs: "HomeServer"):
189189
self.hostname = hs.hostname
190190
self.signing_key = hs.signing_key
191191

192-
self.store = hs.get_datastore()
192+
self.store = hs.get_datastores().main
193193
self.state = hs.get_state_handler()
194194
self._event_auth_handler = hs.get_event_auth_handler()
195195

synapse/events/third_party_rules.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class ThirdPartyEventRules:
143143
def __init__(self, hs: "HomeServer"):
144144
self.third_party_rules = None
145145

146-
self.store = hs.get_datastore()
146+
self.store = hs.get_datastores().main
147147

148148
self._check_event_allowed_callbacks: List[CHECK_EVENT_ALLOWED_CALLBACK] = []
149149
self._on_create_room_callbacks: List[ON_CREATE_ROOM_CALLBACK] = []

synapse/federation/federation_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, hs: "HomeServer"):
3939
self.server_name = hs.hostname
4040
self.keyring = hs.get_keyring()
4141
self.spam_checker = hs.get_spam_checker()
42-
self.store = hs.get_datastore()
42+
self.store = hs.get_datastores().main
4343
self._clock = hs.get_clock()
4444

4545
async def _check_sigs_and_hash(

synapse/federation/sender/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def __init__(self, hs: "HomeServer"):
228228
self.hs = hs
229229
self.server_name = hs.hostname
230230

231-
self.store = hs.get_datastore()
231+
self.store = hs.get_datastores().main
232232
self.state = hs.get_state_handler()
233233

234234
self.clock = hs.get_clock()

synapse/federation/sender/per_destination_queue.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(
7676
):
7777
self._server_name = hs.hostname
7878
self._clock = hs.get_clock()
79-
self._store = hs.get_datastore()
79+
self._store = hs.get_datastores().main
8080
self._transaction_manager = transaction_manager
8181
self._instance_name = hs.get_instance_name()
8282
self._federation_shard_config = hs.config.worker.federation_shard_config
@@ -381,9 +381,8 @@ async def _catch_up_transmission_loop(self) -> None:
381381
)
382382
)
383383

384-
last_successful_stream_ordering = self._last_successful_stream_ordering
385-
386-
if last_successful_stream_ordering is None:
384+
_tmp_last_successful_stream_ordering = self._last_successful_stream_ordering
385+
if _tmp_last_successful_stream_ordering is None:
387386
# if it's still None, then this means we don't have the information
388387
# in our database ­ we haven't successfully sent a PDU to this server
389388
# (at least since the introduction of the feature tracking
@@ -393,6 +392,8 @@ async def _catch_up_transmission_loop(self) -> None:
393392
self._catching_up = False
394393
return
395394

395+
last_successful_stream_ordering: int = _tmp_last_successful_stream_ordering
396+
396397
# get at most 50 catchup room/PDUs
397398
while True:
398399
event_ids = await self._store.get_catch_up_room_event_ids(

synapse/federation/sender/transaction_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class TransactionManager:
5353
def __init__(self, hs: "synapse.server.HomeServer"):
5454
self._server_name = hs.hostname
5555
self.clock = hs.get_clock() # nb must be called this for @measure_func
56-
self._store = hs.get_datastore()
56+
self._store = hs.get_datastores().main
5757
self._transaction_actions = TransactionActions(self._store)
5858
self._transport_layer = hs.get_federation_transport_client()
5959

synapse/federation/transport/server/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def __init__(self, hs: "HomeServer"):
5555
self._clock = hs.get_clock()
5656
self.keyring = hs.get_keyring()
5757
self.server_name = hs.hostname
58-
self.store = hs.get_datastore()
58+
self.store = hs.get_datastores().main
5959
self.federation_domain_whitelist = (
6060
hs.config.federation.federation_domain_whitelist
6161
)

synapse/federation/transport/server/federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def __init__(
746746
server_name: str,
747747
):
748748
super().__init__(hs, authenticator, ratelimiter, server_name)
749-
self._store = self.hs.get_datastore()
749+
self._store = self.hs.get_datastores().main
750750

751751
async def on_GET(
752752
self,

synapse/groups/attestations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class GroupAttestionRenewer:
140140

141141
def __init__(self, hs: "HomeServer"):
142142
self.clock = hs.get_clock()
143-
self.store = hs.get_datastore()
143+
self.store = hs.get_datastores().main
144144
self.assestations = hs.get_groups_attestation_signing()
145145
self.transport_client = hs.get_federation_transport_client()
146146
self.is_mine_id = hs.is_mine_id

synapse/groups/groups_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
class GroupsServerWorkerHandler:
4646
def __init__(self, hs: "HomeServer"):
4747
self.hs = hs
48-
self.store = hs.get_datastore()
48+
self.store = hs.get_datastores().main
4949
self.room_list_handler = hs.get_room_list_handler()
5050
self.auth = hs.get_auth()
5151
self.clock = hs.get_clock()

synapse/handlers/account_data.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
class AccountDataHandler:
3232
def __init__(self, hs: "HomeServer"):
33-
self._store = hs.get_datastore()
33+
self._store = hs.get_datastores().main
3434
self._instance_name = hs.get_instance_name()
3535
self._notifier = hs.get_notifier()
3636

@@ -166,7 +166,7 @@ async def remove_tag_from_room(self, user_id: str, room_id: str, tag: str) -> in
166166

167167
class AccountDataEventSource(EventSource[int, JsonDict]):
168168
def __init__(self, hs: "HomeServer"):
169-
self.store = hs.get_datastore()
169+
self.store = hs.get_datastores().main
170170

171171
def get_current_key(self, direction: str = "f") -> int:
172172
return self.store.get_max_account_data_stream_id()

synapse/handlers/account_validity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class AccountValidityHandler:
4343
def __init__(self, hs: "HomeServer"):
4444
self.hs = hs
4545
self.config = hs.config
46-
self.store = self.hs.get_datastore()
46+
self.store = self.hs.get_datastores().main
4747
self.send_email_handler = self.hs.get_send_email_handler()
4848
self.clock = self.hs.get_clock()
4949

synapse/handlers/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
class AdminHandler:
3131
def __init__(self, hs: "HomeServer"):
32-
self.store = hs.get_datastore()
32+
self.store = hs.get_datastores().main
3333
self.storage = hs.get_storage()
3434
self.state_store = self.storage.state
3535

synapse/handlers/appservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
class ApplicationServicesHandler:
4949
def __init__(self, hs: "HomeServer"):
50-
self.store = hs.get_datastore()
50+
self.store = hs.get_datastores().main
5151
self.is_mine_id = hs.is_mine_id
5252
self.appservice_api = hs.get_application_service_api()
5353
self.scheduler = hs.get_application_service_scheduler()

synapse/handlers/auth.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class AuthHandler:
194194
SESSION_EXPIRE_MS = 48 * 60 * 60 * 1000
195195

196196
def __init__(self, hs: "HomeServer"):
197-
self.store = hs.get_datastore()
197+
self.store = hs.get_datastores().main
198198
self.auth = hs.get_auth()
199199
self.clock = hs.get_clock()
200200
self.checkers: Dict[str, UserInteractiveAuthChecker] = {}
@@ -1183,7 +1183,7 @@ async def validate_login(
11831183

11841184
# No password providers were able to handle this 3pid
11851185
# Check local store
1186-
user_id = await self.hs.get_datastore().get_user_id_by_threepid(
1186+
user_id = await self.hs.get_datastores().main.get_user_id_by_threepid(
11871187
medium, address
11881188
)
11891189
if not user_id:

synapse/handlers/cas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class CasHandler:
6161
def __init__(self, hs: "HomeServer"):
6262
self.hs = hs
6363
self._hostname = hs.hostname
64-
self._store = hs.get_datastore()
64+
self._store = hs.get_datastores().main
6565
self._auth_handler = hs.get_auth_handler()
6666
self._registration_handler = hs.get_registration_handler()
6767

synapse/handlers/deactivate_account.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DeactivateAccountHandler:
2929
"""Handler which deals with deactivating user accounts."""
3030

3131
def __init__(self, hs: "HomeServer"):
32-
self.store = hs.get_datastore()
32+
self.store = hs.get_datastores().main
3333
self.hs = hs
3434
self._auth_handler = hs.get_auth_handler()
3535
self._device_handler = hs.get_device_handler()

synapse/handlers/device.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class DeviceWorkerHandler:
6363
def __init__(self, hs: "HomeServer"):
6464
self.clock = hs.get_clock()
6565
self.hs = hs
66-
self.store = hs.get_datastore()
66+
self.store = hs.get_datastores().main
6767
self.notifier = hs.get_notifier()
6868
self.state = hs.get_state_handler()
6969
self.state_store = hs.get_storage().state
@@ -628,7 +628,7 @@ class DeviceListUpdater:
628628
"Handles incoming device list updates from federation and updates the DB"
629629

630630
def __init__(self, hs: "HomeServer", device_handler: DeviceHandler):
631-
self.store = hs.get_datastore()
631+
self.store = hs.get_datastores().main
632632
self.federation = hs.get_federation_client()
633633
self.clock = hs.get_clock()
634634
self.device_handler = device_handler

synapse/handlers/devicemessage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(self, hs: "HomeServer"):
4343
Args:
4444
hs: server
4545
"""
46-
self.store = hs.get_datastore()
46+
self.store = hs.get_datastores().main
4747
self.notifier = hs.get_notifier()
4848
self.is_mine = hs.is_mine
4949

synapse/handlers/directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, hs: "HomeServer"):
4444
self.state = hs.get_state_handler()
4545
self.appservice_handler = hs.get_application_service_handler()
4646
self.event_creation_handler = hs.get_event_creation_handler()
47-
self.store = hs.get_datastore()
47+
self.store = hs.get_datastores().main
4848
self.config = hs.config
4949
self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search
5050
self.require_membership = hs.config.server.require_membership_for_aliases

synapse/handlers/e2e_keys.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747

4848
class E2eKeysHandler:
4949
def __init__(self, hs: "HomeServer"):
50-
self.store = hs.get_datastore()
50+
self.store = hs.get_datastores().main
5151
self.federation = hs.get_federation_client()
5252
self.device_handler = hs.get_device_handler()
5353
self.is_mine = hs.is_mine
@@ -1335,7 +1335,7 @@ class SigningKeyEduUpdater:
13351335
"""Handles incoming signing key updates from federation and updates the DB"""
13361336

13371337
def __init__(self, hs: "HomeServer", e2e_keys_handler: E2eKeysHandler):
1338-
self.store = hs.get_datastore()
1338+
self.store = hs.get_datastores().main
13391339
self.federation = hs.get_federation_client()
13401340
self.clock = hs.get_clock()
13411341
self.e2e_keys_handler = e2e_keys_handler

synapse/handlers/e2e_room_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class E2eRoomKeysHandler:
4545
"""
4646

4747
def __init__(self, hs: "HomeServer"):
48-
self.store = hs.get_datastore()
48+
self.store = hs.get_datastores().main
4949

5050
# Used to lock whenever a client is uploading key data. This prevents collisions
5151
# between clients trying to upload the details of a new session, given all

0 commit comments

Comments
 (0)