Change CHANNEL_PINS_UPDATE to use guild information from gateway
This changes the channel lookup from O(n) to two amortised O(1) lookups
This commit is contained in:
parent
af8742a911
commit
b4e39668fb
@ -702,19 +702,21 @@ class ConnectionState:
|
|||||||
|
|
||||||
def parse_channel_pins_update(self, data):
|
def parse_channel_pins_update(self, data):
|
||||||
channel_id = int(data['channel_id'])
|
channel_id = int(data['channel_id'])
|
||||||
channel = self.get_channel(channel_id)
|
try:
|
||||||
|
guild = self._get_guild(int(data['guild_id']))
|
||||||
|
except KeyError:
|
||||||
|
guild = None
|
||||||
|
channel = self._get_private_channel(channel_id)
|
||||||
|
else:
|
||||||
|
channel = guild and guild._resolve_channel(channel_id)
|
||||||
|
|
||||||
if channel is None:
|
if channel is None:
|
||||||
log.debug('CHANNEL_PINS_UPDATE referencing an unknown channel ID: %s. Discarding.', channel_id)
|
log.debug('CHANNEL_PINS_UPDATE referencing an unknown channel ID: %s. Discarding.', channel_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
last_pin = utils.parse_time(data['last_pin_timestamp']) if data['last_pin_timestamp'] else None
|
last_pin = utils.parse_time(data['last_pin_timestamp']) if data['last_pin_timestamp'] else None
|
||||||
|
|
||||||
try:
|
if guild is None:
|
||||||
# I have not imported discord.abc in this file
|
|
||||||
# the isinstance check is also 2x slower than just checking this attribute
|
|
||||||
# so we're just gonna check it since it's easier and faster and lazier
|
|
||||||
channel.guild
|
|
||||||
except AttributeError:
|
|
||||||
self.dispatch('private_channel_pins_update', channel, last_pin)
|
self.dispatch('private_channel_pins_update', channel, last_pin)
|
||||||
else:
|
else:
|
||||||
self.dispatch('guild_channel_pins_update', channel, last_pin)
|
self.dispatch('guild_channel_pins_update', channel, last_pin)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user