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

230 files changed

Lines changed: 526 additions & 500 deletions

File tree

Some content is hidden

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

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 = (

0 commit comments

Comments
 (0)