diff options
| author | 2021-08-30 19:11:11 +0200 | |
|---|---|---|
| committer | 2021-08-30 19:11:11 +0200 | |
| commit | 857468ce4efbe26220d4c36a8840a13f89b30c44 (patch) | |
| tree | c5da9af41751093c9d79a616c94975e6a2acad05 | |
| parent | Remove the json argument from the raw command. (#1792) (diff) | |
create a helper function to get the redis key of a doc item
| -rw-r--r-- | bot/exts/info/doc/_redis_cache.py | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/bot/exts/info/doc/_redis_cache.py b/bot/exts/info/doc/_redis_cache.py index ad764816f..0c635bf6e 100644 --- a/bot/exts/info/doc/_redis_cache.py +++ b/bot/exts/info/doc/_redis_cache.py @@ -24,8 +24,7 @@ class DocRedisCache(RedisObject): All keys from a single page are stored together, expiring a week after the first set. """ - url_key = remove_suffix(item.relative_url_path, ".html") - redis_key = f"{self.namespace}:{item.package}:{url_key}" + redis_key = f"{self.namespace}:{item_key(item)}" needs_expire = False with await self._get_pool_connection() as connection: @@ -43,10 +42,8 @@ class DocRedisCache(RedisObject): @namespace_lock async def get(self, item: DocItem) -> Optional[str]: """Return the Markdown content of the symbol `item` if it exists.""" - url_key = remove_suffix(item.relative_url_path, ".html") - with await self._get_pool_connection() as connection: - return await connection.hget(f"{self.namespace}:{item.package}:{url_key}", item.symbol_id, encoding="utf8") + return await connection.hget(f"{self.namespace}:{item_key(item)}", item.symbol_id, encoding="utf8") @namespace_lock async def delete(self, package: str) -> bool: @@ -61,10 +58,6 @@ class DocRedisCache(RedisObject): return False -def remove_suffix(string: str, suffix: str) -> str: - """Remove `suffix` from end of `string`.""" - # TODO replace usages with str.removesuffix on 3.9 - if string.endswith(suffix): - return string[:-len(suffix)] - else: - return string +def item_key(item: DocItem) -> str: + """Get the redis redis key string from `item`.""" + return f"{item.package}:{item.relative_url_path.removesuffix('.html')}" |