From 826ce101fdd4191f366df5ed286a4556ac7411bd Mon Sep 17 00:00:00 2001 From: Rapptz Date: Thu, 8 Jul 2021 21:53:26 -0400 Subject: [PATCH] Change WEBHOOK_UPDATE to use guild information from gateway This changes the lookup from unnecessary O(n) to two amortised O(1) lookups. This event pretty much always has a guild_id so the original code was always a performance bottleneck. --- discord/state.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/discord/state.py b/discord/state.py index e7150426f..4965e531e 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1135,7 +1135,12 @@ class ConnectionState: log.debug('INTEGRATION_DELETE referencing an unknown guild ID: %s. Discarding.', guild_id) def parse_webhooks_update(self, data): - channel = self.get_channel(int(data['channel_id'])) + guild = self._get_guild(int(data['guild_id'])) + if guild is None: + log.debug('WEBHOOKS_UPDATE referencing an unknown guild ID: %s. Discarding', data['guild_id']) + return + + channel = guild.get_channel(int(data['channel_id'])) if channel is not None: self.dispatch('webhooks_update', channel) else: