diff options
| author | 2021-08-30 20:44:49 +0200 | |
|---|---|---|
| committer | 2021-08-30 20:44:49 +0200 | |
| commit | 727ef751ec2bb308d4a2d8bb0e348e438620494c (patch) | |
| tree | cc21fe86d650a12022da9788742337e927d9edff | |
| parent | Prevent erroneous symbols from always raising stale warnings (diff) | |
Delete stale item counters when clearing doc cache
| -rw-r--r-- | bot/exts/info/doc/_cog.py | 1 | ||||
| -rw-r--r-- | bot/exts/info/doc/_redis_cache.py | 12 | 
2 files changed, 13 insertions, 0 deletions
| diff --git a/bot/exts/info/doc/_cog.py b/bot/exts/info/doc/_cog.py index fb9b2584a..6c3110306 100644 --- a/bot/exts/info/doc/_cog.py +++ b/bot/exts/info/doc/_cog.py @@ -439,6 +439,7 @@ class DocCog(commands.Cog):      ) -> None:          """Clear the persistent redis cache for `package`."""          if await doc_cache.delete(package_name): +            await self.item_fetcher.stale_inventory_notifier.symbol_counter.delete()              await ctx.send(f"Successfully cleared the cache for `{package_name}`.")          else:              await ctx.send("No keys matching the package found.") diff --git a/bot/exts/info/doc/_redis_cache.py b/bot/exts/info/doc/_redis_cache.py index 3fa3460ca..05871eef7 100644 --- a/bot/exts/info/doc/_redis_cache.py +++ b/bot/exts/info/doc/_redis_cache.py @@ -73,6 +73,18 @@ class StaleItemCounter(RedisObject):              await connection.expire(key, WEEK_SECONDS * 3)              return int(await connection.incr(key)) +    @namespace_lock +    async def delete(self, package: str) -> bool: +        """Remove all values for `package`; return True if at least one key was deleted, False otherwise.""" +        with await self._get_pool_connection() as connection: +            package_keys = [ +                package_key async for package_key in connection.iscan(match=f"{self.namespace}:{package}:*") +            ] +            if package_keys: +                await connection.delete(*package_keys) +                return True +            return False +  def item_key(item: DocItem) -> str:      """Get the redis redis key string from `item`.""" | 
