diff options
| author | 2020-07-17 21:33:14 +0200 | |
|---|---|---|
| committer | 2020-07-17 21:33:14 +0200 | |
| commit | 98c325f316038536270c87d0f767e2c18c215df7 (patch) | |
| tree | f83e79e323c5594d4568f8b1b469841a74ee4a5e | |
| parent | Kaizen: Move OffTopicName to converters.py. (diff) | |
Cache AllowDenyList data at bot startup.
We shouldn't be making an API call for every single message posted, so
what we're gonna do is cache the data in the Bot, and then update the
cache whenever we make changes to it via our new AllowDenyList cog.
Since this cog will be the only way to make changes to this, this level
of lazy caching should be enough to always keep the cache up to date.
| -rw-r--r-- | bot/bot.py | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/bot/bot.py b/bot/bot.py index 313652d11..b170be6d3 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -49,6 +49,10 @@ class Bot(commands.Bot): self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot") + async def _cache_allow_deny_list_data(self) -> None: + """Cache all the data in the AllowDenyList on the site.""" + self.allow_deny_list_cache = await self.api_client.get('bot/allow_deny_lists') + async def _create_redis_session(self) -> None: """ Create the Redis connection pool, and then open the redis event gate. @@ -159,6 +163,9 @@ class Bot(commands.Bot): self.http_session = aiohttp.ClientSession(connector=self._connector) self.api_client.recreate(force=True, connector=self._connector) + # Build the AllowDenyList cache + self.loop.create_task(self._cache_allow_deny_list_data()) + async def on_guild_available(self, guild: discord.Guild) -> None: """ Set the internal guild available event when constants.Guild.id becomes available. |