diff options
| author | Rapptz <[email protected]> | 2021-07-08 21:53:26 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-07-08 21:53:26 -0400 |
| commit | 826ce101fdd4191f366df5ed286a4556ac7411bd (patch) | |
| tree | 779cbc8e29900f8c4c0f4c44a54e44e6197f7a7a /discord/state.py | |
| parent | Change CHANNEL_PINS_UPDATE to use guild information from gateway (diff) | |
| download | discord.py-826ce101fdd4191f366df5ed286a4556ac7411bd.tar.xz discord.py-826ce101fdd4191f366df5ed286a4556ac7411bd.zip | |
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.
Diffstat (limited to 'discord/state.py')
| -rw-r--r-- | discord/state.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/discord/state.py b/discord/state.py index e7150426..4965e531 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: |