From 67dee5d73ac1a38f664c50f5ca4068a0f3827064 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sat, 31 Aug 2024 08:29:05 -0400 Subject: [PATCH] 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. --- discord/message.py | 2 +- discord/state.py | 6 ------ discord/webhook/async_.py | 5 ----- 3 files changed, 1 insertion(+), 12 deletions(-) diff --git a/discord/message.py b/discord/message.py index da66e3a3c..816f81a83 100644 --- a/discord/message.py +++ b/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 diff --git a/discord/state.py b/discord/state.py index bfbca998e..b69dcfd1f 100644 --- a/discord/state.py +++ b/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) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index be3208ebc..ee4c08444 100644 --- a/discord/webhook/async_.py +++ b/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)