diff --git a/synapse/logging/opentracing.py b/synapse/logging/opentracing.py index 6e4e029163..3037097cb2 100644 --- a/synapse/logging/opentracing.py +++ b/synapse/logging/opentracing.py @@ -943,6 +943,10 @@ def _custom_sync_async_decorator( async def _wrapper( *args: P.args, **kwargs: P.kwargs ) -> Any: # Return type is RInner + # Short-circuit: if opentracing was disabled after decoration time + # (init_tracer sets opentracing=None), skip all wrapping overhead. + if opentracing is None: + return await func(*args, **kwargs) # type: ignore[unreachable] # type-ignore: func() returns R, but mypy doesn't know that R is # Awaitable here. with wrapping_logic(func, *args, **kwargs): # type: ignore[arg-type] @@ -953,6 +957,11 @@ def _custom_sync_async_decorator( # `@defer.inlineCallbacks` or that return a `Deferred` or other `Awaitable`. @wraps(func) def _wrapper(*args: P.args, **kwargs: P.kwargs) -> Any: + # Short-circuit: if opentracing was disabled after decoration time + # (init_tracer sets opentracing=None), skip all wrapping overhead. + if opentracing is None: + return func(*args, **kwargs) # type: ignore[unreachable] + scope = wrapping_logic(func, *args, **kwargs) scope.__enter__() diff --git a/synapse/util/caches/descriptors.py b/synapse/util/caches/descriptors.py index 48c8f8f043..d416ca97ac 100644 --- a/synapse/util/caches/descriptors.py +++ b/synapse/util/caches/descriptors.py @@ -455,9 +455,7 @@ class DeferredCacheListDescriptor(_CacheDescriptorBase): cache_entry.error_bulk(cache, missing, f) args_to_call = dict(arg_dict) - args_to_call[list_name] = { - cache_key_to_arg(key) for key in missing - } + args_to_call[list_name] = {cache_key_to_arg(key) for key in missing} # dispatch the call, and attach the two handlers missing_d = defer.maybeDeferred( @@ -710,4 +708,4 @@ def _get_cache_key_gen( pos += 1 else: if inc: - yield param_defaults[nm] \ No newline at end of file + yield param_defaults[nm]