Skip to content

Commit bf5fbd3

Browse files
committed
fix(serverlogs): cache usage when no log is enabled
1 parent 6ff4c47 commit bf5fbd3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

modules/serverlogs/serverlogs.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ class ServerLogs(commands.Cog):
3838
def __init__(self, bot: Axobot):
3939
self.bot = bot
4040
self.file = "serverlogs"
41-
self.cache = TTLCache[int, dict[int, list[str]]](maxsize=10_000, ttl=3600*4)
41+
# 10min cache of guild_id -> [channel_id, logs]
42+
self.cache = TTLCache[int, dict[int, list[str]]](maxsize=10_000, ttl=60 * 10)
43+
# guild_id -> list of logs to send in the next log batch
4244
self.to_send: dict[int, list[LogToSend]] = {}
4345
self.auditlogs_timeout = 3 # seconds
4446
self.voice_join_timestamps: dict[tuple[int, int], float] = {}
@@ -77,7 +79,7 @@ async def validate_logs(self,
7779

7880
async def db_get_from_channel(self, guild_id: int, channel_id: int, use_cache: bool=True) -> list[str]:
7981
"Get enabled logs for a channel"
80-
if use_cache and (cached := self.cache.get(guild_id)) and channel_id in cached:
82+
if use_cache and (cached := self.cache.get(guild_id)) is not None and channel_id in cached:
8183
return cached[channel_id]
8284
query = "SELECT kind FROM serverlogs WHERE guild = %s AND channel = %s AND beta = %s"
8385
async with self.bot.db_main.read(query, (guild_id, channel_id, self.bot.beta)) as query_results:
@@ -86,7 +88,7 @@ async def db_get_from_channel(self, guild_id: int, channel_id: int, use_cache: b
8688
async def db_get_from_guild(self, guild_id: int, use_cache: bool=True) -> dict[int, list[str]]:
8789
"""Get enabled logs for a guild
8890
Returns a map of ChannelID -> list of enabled logs"""
89-
if use_cache and (cached := self.cache.get(guild_id)):
91+
if use_cache and (cached := self.cache.get(guild_id)) is not None:
9092
return cached
9193
query = "SELECT channel, kind FROM serverlogs WHERE guild = %s AND beta = %s"
9294
async with self.bot.db_main.read(query, (guild_id, self.bot.beta)) as query_results:

0 commit comments

Comments
 (0)