diff options
author | 2022-07-23 23:54:17 +0100 | |
---|---|---|
committer | 2022-08-14 19:43:53 +0100 | |
commit | 8ef517d9bf8d64f679fa3b071b6d723a11332548 (patch) | |
tree | a318b3e898b5db45c8b2c7d8af86bcb1244393e1 | |
parent | Update any calls to Redis 'iscan' to the new name 'scan_iter' (diff) |
Add back a lock to DocRedisCache.set based on the DocItem
-rw-r--r-- | bot/exts/info/doc/_redis_cache.py | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/bot/exts/info/doc/_redis_cache.py b/bot/exts/info/doc/_redis_cache.py index 2a2f5e4b4..ef9abd981 100644 --- a/bot/exts/info/doc/_redis_cache.py +++ b/bot/exts/info/doc/_redis_cache.py @@ -8,6 +8,7 @@ from typing import Optional, TYPE_CHECKING from async_rediscache.types.base import RedisObject from bot.log import get_logger +from bot.utils.lock import lock if TYPE_CHECKING: from ._cog import DocItem @@ -17,6 +18,12 @@ WEEK_SECONDS = int(datetime.timedelta(weeks=1).total_seconds()) log = get_logger(__name__) +def serialize_resource_id_from_doc_item(bound_args: dict) -> str: + """Return the redis_key of the DocItem `item` from the bound args of DocRedisCache.set.""" + item: DocItem = bound_args["item"] + return f"doc:{item_key(item)}" + + class DocRedisCache(RedisObject): """Interface for redis functionality needed by the Doc cog.""" @@ -24,6 +31,7 @@ class DocRedisCache(RedisObject): super().__init__(*args, **kwargs) self._set_expires = dict[str, float]() + @lock("DocRedisCache.set", serialize_resource_id_from_doc_item, wait=True) async def set(self, item: DocItem, value: str) -> None: """ Set the Markdown `value` for the symbol `item`. |