Browse Source

Remove _get_poll lookup in Message constructor

This was triggering a terrible performance regression for no good
reason for all created messages that didn't have a poll, which is
essentially 99.99% of messages leading to MESSAGE_CREATE dispatches
having degraded performance.
pull/10109/head
Rapptz 10 months ago
committed by dolfies
parent
commit
67dee5d73a
  1. 2
      discord/message.py
  2. 6
      discord/state.py
  3. 5
      discord/webhook/async_.py

2
discord/message.py

@ -1698,7 +1698,7 @@ class Message(PartialMessage, Hashable):
try:
self.poll = Poll._from_data(data=data['poll'], message=self, state=state)
except KeyError:
self.poll = state._get_poll(self.id)
pass
try:
# If the channel doesn't have a guild attribute, we handle that

6
discord/state.py

@ -1318,12 +1318,6 @@ class ConnectionState:
else utils.find(lambda m: m.id == msg_id, reversed(self._call_message_cache.values()))
)
def _get_poll(self, msg_id: Optional[int]) -> Optional[Poll]:
message = self._get_message(msg_id)
if not message:
return
return message.poll
def _add_guild_from_data(self, data: GuildPayload) -> Guild:
guild = self.create_guild(data)
self._add_guild(guild)

5
discord/webhook/async_.py

@ -510,11 +510,6 @@ class _WebhookState:
return self._parent._get_guild(guild_id)
return None
def _get_poll(self, msg_id: Optional[int]) -> Optional[Poll]:
if self._parent is not None:
return self._parent._get_poll(msg_id)
return None
def store_user(self, data: Union[UserPayload, PartialUserPayload], *, cache: bool = True) -> BaseUser:
if self._parent is not None:
return self._parent.store_user(data, cache=cache)

Loading…
Cancel
Save