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

Commit 5a15377

Browse files
authored
remove HomeServer.get_config (#9815)
Every single time I want to access the config object, I have to remember whether or not we use `get_config`. Let's just get rid of it.
1 parent 936e698 commit 5a15377

File tree

9 files changed

+16
-18
lines changed

9 files changed

+16
-18
lines changed

changelog.d/9815.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Replace `HomeServer.get_config()` with inline references.

synapse/app/generic_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
405405
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
406406
)
407407
elif listener.type == "metrics":
408-
if not self.get_config().enable_metrics:
408+
if not self.config.enable_metrics:
409409
logger.warning(
410410
(
411411
"Metrics listener configured, but "

synapse/app/homeserver.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def _configure_named_resource(self, name, compress=False):
191191
}
192192
)
193193

194-
if self.get_config().threepid_behaviour_email == ThreepidBehaviour.LOCAL:
194+
if self.config.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
195195
from synapse.rest.synapse.client.password_reset import (
196196
PasswordResetSubmitTokenResource,
197197
)
@@ -230,7 +230,7 @@ def _configure_named_resource(self, name, compress=False):
230230
)
231231

232232
if name in ["media", "federation", "client"]:
233-
if self.get_config().enable_media_repo:
233+
if self.config.enable_media_repo:
234234
media_repo = self.get_media_repository_resource()
235235
resources.update(
236236
{MEDIA_PREFIX: media_repo, LEGACY_MEDIA_PREFIX: media_repo}
@@ -244,7 +244,7 @@ def _configure_named_resource(self, name, compress=False):
244244
resources[SERVER_KEY_V2_PREFIX] = KeyApiV2Resource(self)
245245

246246
if name == "webclient":
247-
webclient_loc = self.get_config().web_client_location
247+
webclient_loc = self.config.web_client_location
248248

249249
if webclient_loc is None:
250250
logger.warning(
@@ -265,7 +265,7 @@ def _configure_named_resource(self, name, compress=False):
265265
# https://twistedmatrix.com/trac/ticket/7678
266266
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)
267267

268-
if name == "metrics" and self.get_config().enable_metrics:
268+
if name == "metrics" and self.config.enable_metrics:
269269
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)
270270

271271
if name == "replication":
@@ -274,17 +274,17 @@ def _configure_named_resource(self, name, compress=False):
274274
return resources
275275

276276
def start_listening(self, listeners: Iterable[ListenerConfig]):
277-
config = self.get_config()
278-
279-
if config.redis_enabled:
277+
if self.config.redis_enabled:
280278
# If redis is enabled we connect via the replication command handler
281279
# in the same way as the workers (since we're effectively a client
282280
# rather than a server).
283281
self.get_tcp_replication().start_replication(self)
284282

285283
for listener in listeners:
286284
if listener.type == "http":
287-
self._listening_services.extend(self._listener_http(config, listener))
285+
self._listening_services.extend(
286+
self._listener_http(self.config, listener)
287+
)
288288
elif listener.type == "manhole":
289289
_base.listen_manhole(
290290
listener.bind_addresses, listener.port, manhole_globals={"hs": self}
@@ -298,7 +298,7 @@ def start_listening(self, listeners: Iterable[ListenerConfig]):
298298
for s in services:
299299
reactor.addSystemEventTrigger("before", "shutdown", s.stopListening)
300300
elif listener.type == "metrics":
301-
if not self.get_config().enable_metrics:
301+
if not self.config.enable_metrics:
302302
logger.warning(
303303
(
304304
"Metrics listener configured, but "

synapse/crypto/keyring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ async def get_keys(
501501
class BaseV2KeyFetcher(KeyFetcher):
502502
def __init__(self, hs: "HomeServer"):
503503
self.store = hs.get_datastore()
504-
self.config = hs.get_config()
504+
self.config = hs.config
505505

506506
async def process_v2_response(
507507
self, from_server: str, response_json: JsonDict, time_added_ms: int

synapse/federation/federation_server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def __init__(self, hs: "HomeServer"):
136136
) # type: ResponseCache[Tuple[str, str]]
137137

138138
self._federation_metrics_domains = (
139-
hs.get_config().federation.federation_metrics_domains
139+
hs.config.federation.federation_metrics_domains
140140
)
141141

142142
async def on_backfill_request(

synapse/federation/sender/transaction_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, hs: "synapse.server.HomeServer"):
5656
self._transport_layer = hs.get_federation_transport_client()
5757

5858
self._federation_metrics_domains = (
59-
hs.get_config().federation.federation_metrics_domains
59+
hs.config.federation.federation_metrics_domains
6060
)
6161

6262
# HACK to get unique tx id

synapse/rest/media/v1/config_resource.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MediaConfigResource(DirectServeJsonResource):
3030

3131
def __init__(self, hs: "HomeServer"):
3232
super().__init__()
33-
config = hs.get_config()
33+
config = hs.config
3434
self.clock = hs.get_clock()
3535
self.auth = hs.get_auth()
3636
self.limits_dict = {"m.upload.size": config.max_upload_size}

synapse/server.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,6 @@ def get_datastores(self) -> Databases:
323323

324324
return self.datastores
325325

326-
def get_config(self) -> HomeServerConfig:
327-
return self.config
328-
329326
@cache_in_self
330327
def get_distributor(self) -> Distributor:
331328
return Distributor()

tests/app/test_openid_listener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def test_openid_listener(self, names, expectation):
109109
}
110110

111111
# Listen with the config
112-
self.hs._listener_http(self.hs.get_config(), parse_listener_def(config))
112+
self.hs._listener_http(self.hs.config, parse_listener_def(config))
113113

114114
# Grab the resource from the site that was told to listen
115115
site = self.reactor.tcpServers[0][1]

0 commit comments

Comments
 (0)