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

Commit 8955c76

Browse files
committed
Rebase master & re-apply linting/type fixes
1 parent 8019ed3 commit 8955c76

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

synapse/_scripts/update_synapse_database.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ def main() -> None:
9898
hs_config = yaml.safe_load(args.database_config)
9999

100100
if "database" not in hs_config and "databases" not in hs_config:
101-
sys.stderr.write("The configuration file must have a 'database' or 'databases' section.\n")
101+
sys.stderr.write(
102+
"The configuration file must have a 'database' or 'databases' section.\n"
103+
)
102104
sys.exit(4)
103105

104106
config = HomeServerConfig()

synapse/storage/databases/main/roommember.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ def __init__(
121121
)
122122

123123
external_sharded_cache = self.hs.get_external_sharded_cache()
124-
self._get_joined_profiles_from_event_ids.enable_redis_cache(external_sharded_cache)
124+
self._get_joined_profiles_from_event_ids.enable_redis_cache( # type: ignore
125+
external_sharded_cache
126+
)
125127

126128
@wrap_as_background_process("_count_known_servers")
127129
async def _count_known_servers(self) -> int:

synapse/util/caches/descriptors.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
from twisted.python.failure import Failure
4141

4242
from synapse.logging.context import make_deferred_yieldable, preserve_fn
43+
from synapse.replication.tcp.external_sharded_cache import ExternalShardedCache
4344
from synapse.util import unwrapFirstError
4445
from synapse.util.async_helpers import delay_cancellation
4546
from synapse.util.caches.deferred_cache import DeferredCache
@@ -59,6 +60,7 @@ class _CachedFunction(Generic[F]):
5960
prefill: Any = None
6061
cache: Any = None
6162
num_args: Any = None
63+
tree: bool = False
6264

6365
__name__: str
6466

@@ -529,7 +531,7 @@ def errback_all(f: Failure) -> None:
529531
else:
530532
return defer.succeed(results)
531533

532-
def enable_redis_cache(external_sharded_cache):
534+
def enable_redis_cache(external_sharded_cache: ExternalShardedCache) -> None:
533535
if getattr(cached_method, "redis_enabled", False):
534536
return
535537

@@ -545,13 +547,14 @@ def enable_redis_cache(external_sharded_cache):
545547
assert not self.add_cache_context
546548

547549
# Cache invalidations are not allowed with Redis backed caches (currently)
548-
def block_invalidate():
550+
def block_invalidate() -> None:
549551
raise Exception("Cannot invalidate Redis backed @cachedList")
552+
550553
cached_method.invalidate = block_invalidate
551554
cached_method.invalidate_all = block_invalidate
552555
cached_method.redis_enabled = True
553556

554-
wrapped.enable_redis_cache = enable_redis_cache
557+
wrapped.enable_redis_cache = enable_redis_cache # type: ignore
555558
obj.__dict__[self.orig.__name__] = wrapped
556559

557560
return wrapped

synapse/util/caches/redis_caches.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
from functools import wraps
2-
from typing import TYPE_CHECKING, Any, Generic, Optional, Union
2+
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, List, Optional, Union
33

44
from synapse.util.caches.lrucache import KT, VT, AsyncLruCache, T
55

66
if TYPE_CHECKING:
77
from synapse.replication.tcp.external_sharded_cache import ExternalShardedCache
88

99

10-
def redisCachedList(redis_shard_cache, cache_name, list_name):
11-
def decorator(f):
10+
def redisCachedList(
11+
redis_shard_cache: ExternalShardedCache, cache_name: str, list_name: str
12+
) -> Callable:
13+
def decorator(f: Callable) -> Callable:
1214
@wraps(f)
13-
async def _wrapped(**kwargs):
14-
keys = kwargs[list_name]
15+
async def _wrapped(**kwargs: Any) -> Dict[str, Any]:
16+
keys: List[str] = kwargs[list_name]
1517
values = await redis_shard_cache.mget(cache_name, keys)
1618

17-
missing_keys = set(keys) - set(values.keys())
19+
missing_keys = list(set(keys) - set(values.keys()))
1820
kwargs[list_name] = missing_keys
1921
missing_values = await f(**kwargs)
2022
await redis_shard_cache.mset(cache_name, missing_values)

0 commit comments

Comments
 (0)