From 982651af7ac7cb99571a6da1aba929172b4edbf8 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Fri, 16 Oct 2026 04:36:00 -0400 Subject: [PATCH] perf: resolve the log channel from the guild cache before fetch_channel T3-19: _get_channel did an HTTP fetch_channel (GET /channels/{id}) on every guild-routed log line, in both the self.channel and settings paths. try guild.get_channel first; fetch only on a cache miss. same channel, same ValueError normalization. Signed-off-by: disqualifier --- src/dpy_logger/dpy_logger.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/dpy_logger/dpy_logger.py b/src/dpy_logger/dpy_logger.py index be839a2..bbf820c 100644 --- a/src/dpy_logger/dpy_logger.py +++ b/src/dpy_logger/dpy_logger.py @@ -130,7 +130,10 @@ class DPYLogger: raise ValueError("[dpy_logger] no guild available for logging") async def _get_channel(self, guild, override=False): - """resolve the log channel, preferring self.channel when the guild matches""" + """resolve the log channel, preferring self.channel when the guild matches + + the guild's channel cache is tried first; fetch_channel (an HTTP GET) only runs on a + cache miss (e.g. a fetched, uncached guild)""" if not guild: raise ValueError("[dpy_logger] cannot resolve channel without a guild") @@ -141,7 +144,7 @@ class DPYLogger: # fetch_channel raises NotFound/Forbidden/HTTPException/InvalidData (a # ClientException, not an HTTPException); normalize all to ValueError try: - channel = await guild.fetch_channel(self.channel) + channel = guild.get_channel(self.channel) or await guild.fetch_channel(self.channel) except (discord.HTTPException, discord.ClientException) as error: raise ValueError(f"[dpy_logger] could not fetch channel {self.channel}: {error}") from error if not isinstance(channel, discord.TextChannel): @@ -153,7 +156,7 @@ class DPYLogger: except KeyError as error: raise ValueError(f"[dpy_logger] no log channel configured for guild {guild.id}") from error try: - channel = await guild.fetch_channel(channel_id) + channel = guild.get_channel(channel_id) or await guild.fetch_channel(channel_id) except (discord.HTTPException, discord.ClientException) as error: raise ValueError(f"[dpy_logger] could not fetch channel {channel_id}: {error}") from error if not isinstance(channel, discord.TextChannel):