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

Commit 01c88a0

Browse files
authored
Use direct references for some configuration variables (#10798)
Instead of proxying through the magic getter of the RootConfig object. This should be more performant (and is more explicit).
1 parent 9f11107 commit 01c88a0

Some content is hidden

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

66 files changed

+152
-133
lines changed

changelog.d/10798.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use direct references to config flags.

synapse/api/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def __init__(self, hs_config):
4141
"""
4242
if hs_config.form_secret is None:
4343
raise ConfigError("form_secret not set in config")
44-
if hs_config.public_baseurl is None:
44+
if hs_config.server.public_baseurl is None:
4545
raise ConfigError("public_baseurl not set in config")
4646

4747
self._hmac_secret = hs_config.form_secret.encode("utf-8")
48-
self._public_baseurl = hs_config.public_baseurl
48+
self._public_baseurl = hs_config.server.public_baseurl
4949

5050
def build_user_consent_uri(self, user_id):
5151
"""Build a URI which we can give to the user to do their privacy

synapse/app/_base.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def start_worker_reactor(appname, config, run_command=reactor.run):
8282
run_command (Callable[]): callable that actually runs the reactor
8383
"""
8484

85-
logger = logging.getLogger(config.worker_app)
85+
logger = logging.getLogger(config.worker.worker_app)
8686

8787
start_reactor(
8888
appname,
@@ -398,7 +398,7 @@ def run_sighup(*args, **kwargs):
398398

399399
# If background tasks are running on the main process, start collecting the
400400
# phone home stats.
401-
if hs.config.run_background_tasks:
401+
if hs.config.worker.run_background_tasks:
402402
start_phone_stats_home(hs)
403403

404404
# We now freeze all allocated objects in the hopes that (almost)
@@ -433,9 +433,13 @@ def setup_sentry(hs):
433433

434434
# We set some default tags that give some context to this instance
435435
with sentry_sdk.configure_scope() as scope:
436-
scope.set_tag("matrix_server_name", hs.config.server_name)
436+
scope.set_tag("matrix_server_name", hs.config.server.server_name)
437437

438-
app = hs.config.worker_app if hs.config.worker_app else "synapse.app.homeserver"
438+
app = (
439+
hs.config.worker.worker_app
440+
if hs.config.worker.worker_app
441+
else "synapse.app.homeserver"
442+
)
439443
name = hs.get_instance_name()
440444
scope.set_tag("worker_app", app)
441445
scope.set_tag("worker_name", name)

synapse/app/admin_cmd.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ def start(config_options):
178178
sys.stderr.write("\n" + str(e) + "\n")
179179
sys.exit(1)
180180

181-
if config.worker_app is not None:
182-
assert config.worker_app == "synapse.app.admin_cmd"
181+
if config.worker.worker_app is not None:
182+
assert config.worker.worker_app == "synapse.app.admin_cmd"
183183

184184
# Update the config with some basic overrides so that don't have to specify
185185
# a full worker config.
186-
config.worker_app = "synapse.app.admin_cmd"
186+
config.worker.worker_app = "synapse.app.admin_cmd"
187187

188188
if (
189189
not config.worker_daemonize
@@ -196,7 +196,7 @@ def start(config_options):
196196

197197
# Explicitly disable background processes
198198
config.update_user_directory = False
199-
config.run_background_tasks = False
199+
config.worker.run_background_tasks = False
200200
config.start_pushers = False
201201
config.pusher_shard_config.instances = []
202202
config.send_federation = False
@@ -205,7 +205,7 @@ def start(config_options):
205205
synapse.events.USE_FROZEN_DICTS = config.use_frozen_dicts
206206

207207
ss = AdminCmdServer(
208-
config.server_name,
208+
config.server.server_name,
209209
config=config,
210210
version_string="Synapse/" + get_version_string(synapse),
211211
)

synapse/app/generic_worker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def start(config_options):
416416
sys.exit(1)
417417

418418
# For backwards compatibility let any of the old app names.
419-
assert config.worker_app in (
419+
assert config.worker.worker_app in (
420420
"synapse.app.appservice",
421421
"synapse.app.client_reader",
422422
"synapse.app.event_creator",
@@ -430,7 +430,7 @@ def start(config_options):
430430
"synapse.app.user_dir",
431431
)
432432

433-
if config.worker_app == "synapse.app.appservice":
433+
if config.worker.worker_app == "synapse.app.appservice":
434434
if config.appservice.notify_appservices:
435435
sys.stderr.write(
436436
"\nThe appservices must be disabled in the main synapse process"
@@ -446,7 +446,7 @@ def start(config_options):
446446
# For other worker types we force this to off.
447447
config.appservice.notify_appservices = False
448448

449-
if config.worker_app == "synapse.app.user_dir":
449+
if config.worker.worker_app == "synapse.app.user_dir":
450450
if config.server.update_user_directory:
451451
sys.stderr.write(
452452
"\nThe update_user_directory must be disabled in the main synapse process"
@@ -469,7 +469,7 @@ def start(config_options):
469469
synapse.metrics.MIN_TIME_BETWEEN_GCS = config.server.gc_seconds
470470

471471
hs = GenericWorkerServer(
472-
config.server_name,
472+
config.server.server_name,
473473
config=config,
474474
version_string="Synapse/" + get_version_string(synapse),
475475
)

synapse/app/homeserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def setup(config_options):
350350
synapse.metrics.MIN_TIME_BETWEEN_GCS = config.server.gc_seconds
351351

352352
hs = SynapseHomeServer(
353-
config.server_name,
353+
config.server.server_name,
354354
config=config,
355355
version_string="Synapse/" + get_version_string(synapse),
356356
)

synapse/app/phone_stats_home.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):
7373

7474
store = hs.get_datastore()
7575

76-
stats["homeserver"] = hs.config.server_name
76+
stats["homeserver"] = hs.config.server.server_name
7777
stats["server_context"] = hs.config.server_context
7878
stats["timestamp"] = now
7979
stats["uptime_seconds"] = uptime

synapse/config/logger.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def _setup_stdlib_logging(config, log_config_path, logBeginner: LogBeginner) ->
223223
# writes.
224224

225225
log_context_filter = LoggingContextFilter()
226-
log_metadata_filter = MetadataFilter({"server_name": config.server_name})
226+
log_metadata_filter = MetadataFilter({"server_name": config.server.server_name})
227227
old_factory = logging.getLogRecordFactory()
228228

229229
def factory(*args, **kwargs):
@@ -335,5 +335,5 @@ def setup_logging(
335335
# Log immediately so we can grep backwards.
336336
logging.warning("***** STARTING SERVER *****")
337337
logging.warning("Server %s version %s", sys.argv[0], get_version_string(synapse))
338-
logging.info("Server hostname: %s", config.server_name)
338+
logging.info("Server hostname: %s", config.server.server_name)
339339
logging.info("Instance name: %s", hs.get_instance_name())

synapse/events/validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def validate_new(self, event: EventBase, config: HomeServerConfig):
8888
self._validate_retention(event)
8989

9090
if event.type == EventTypes.ServerACL:
91-
if not server_matches_acl_event(config.server_name, event):
91+
if not server_matches_acl_event(config.server.server_name, event):
9292
raise SynapseError(
9393
400, "Can't create an ACL event that denies the local server"
9494
)

synapse/federation/sender/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ def __init__(self, hs: "HomeServer"):
281281
self._queues_awaiting_rr_flush_by_room: Dict[str, Set[PerDestinationQueue]] = {}
282282

283283
self._rr_txn_interval_per_room_ms = (
284-
1000.0 / hs.config.federation_rr_transactions_per_room_per_second
284+
1000.0
285+
/ hs.config.ratelimiting.federation_rr_transactions_per_room_per_second
285286
)
286287

287288
# wake up destinations that have outstanding PDUs to be caught up

0 commit comments

Comments
 (0)