Browse Source

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.
pull/7192/head
Rapptz 4 years ago
parent
commit
826ce101fd
  1. 7
      discord/state.py

7
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:

Loading…
Cancel
Save