Browse Source

Removes the caching behavior of Member.roles

- fixes 4087
- This intentionally uses some internals in both Member.roles and
Member.top_role to retain as much performance as possible while
removing the cache
pull/4178/head
Michael H 5 years ago
committed by GitHub
parent
commit
7bef78284f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      discord/member.py

19
discord/member.py

@ -161,7 +161,7 @@ class Member(discord.abc.Messageable, _BaseUser):
Nitro boost on the guild, if available. This could be ``None``.
"""
__slots__ = ('_roles', '_cs_roles', 'joined_at', 'premium_since', '_client_status',
__slots__ = ('_roles', 'joined_at', 'premium_since', '_client_status',
'activities', 'guild', 'nick', '_user', '_state')
def __init__(self, *, data, guild, state):
@ -234,11 +234,6 @@ class Member(discord.abc.Messageable, _BaseUser):
self.activities = member.activities
self._state = member._state
try:
del self._cs_roles
except AttributeError:
pass
# Reference will not be copied unless necessary by PRESENCE_UPDATE
# See below
self._user = member._user
@ -250,10 +245,6 @@ class Member(discord.abc.Messageable, _BaseUser):
def _update_roles(self, data):
self._roles = utils.SnowflakeList(map(int, data['roles']))
try:
del self._cs_roles
except AttributeError:
pass
def _update(self, data):
# the nickname change is optional,
@ -344,7 +335,7 @@ class Member(discord.abc.Messageable, _BaseUser):
"""
return self.colour
@utils.cached_slot_property('_cs_roles')
@property
def roles(self):
"""List[:class:`Role`]: A :class:`list` of :class:`Role` that the member belongs to. Note
that the first element of this list is always the default '@everyone'
@ -434,7 +425,11 @@ class Member(discord.abc.Messageable, _BaseUser):
This is useful for figuring where a member stands in the role
hierarchy chain.
"""
return self.roles[-1]
guild = self.guild
if len(self._roles) == 0:
return guild.default_role
return max(guild.get_role(rid) or guild.default_role for rid in self._roles)
@property
def guild_permissions(self):

Loading…
Cancel
Save