Revert "Move global user storage from WeakValueDictionary to dict"

This reverts commit cb2363f0fd.

This lead to memory leaks due to insufficient tracking, assuming that
the members intent was enabled.
This commit is contained in:
Rapptz
2022-02-17 07:25:30 -05:00
parent 8b96822ca1
commit 940bdb988a
2 changed files with 16 additions and 53 deletions

View File

@ -429,29 +429,12 @@ class User(BaseUser, discord.abc.Messageable):
Specifies if the user is a system user (i.e. represents Discord officially).
"""
__slots__ = ('_stored',)
def __init__(self, *, state: ConnectionState, data: UserPayload) -> None:
super().__init__(state=state, data=data)
self._stored: bool = False
__slots__ = ('__weakref__',)
def __repr__(self) -> str:
return f'<User id={self.id} name={self.name!r} discriminator={self.discriminator!r} bot={self.bot}>'
def __del__(self) -> None:
try:
if self._stored:
self._state.deref_user(self.id)
except Exception:
pass
@classmethod
def _copy(cls, user: User):
self = super()._copy(user)
self._stored = False
return self
async def _get_channel(self) -> DMChannel:
async def _get_channel(self):
ch = await self.create_dm()
return ch