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/9934/head
Rapptz 7 months ago
parent
commit
733c583b72
  1. 2
      discord/message.py
  2. 6
      discord/state.py
  3. 5
      discord/webhook/async_.py

2
discord/message.py

@ -1849,7 +1849,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

@ -510,12 +510,6 @@ class ConnectionState(Generic[ClientT]):
def _get_message(self, msg_id: Optional[int]) -> Optional[Message]:
return utils.find(lambda m: m.id == msg_id, reversed(self._messages)) if self._messages else None
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 = Guild(data=data, state=self)
self._add_guild(guild)

5
discord/webhook/async_.py

@ -721,11 +721,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