Keep track of Emoji instances myself.
WeakValueDictionary cleans up too late and brings too little benefit. Also clean up the state when the first READY is encountered for AutoShardedClient and when any READY is encountered in regular Client.
This commit is contained in:
parent
e1c32626ba
commit
7f58853e3a
@ -73,7 +73,7 @@ class Emoji(Hashable):
|
|||||||
A list of :class:`Role` that is allowed to use this emoji. If roles is empty,
|
A list of :class:`Role` that is allowed to use this emoji. If roles is empty,
|
||||||
the emoji is unrestricted.
|
the emoji is unrestricted.
|
||||||
"""
|
"""
|
||||||
__slots__ = ('require_colons', 'managed', 'id', 'name', 'roles', 'guild', '_state', '__weakref__')
|
__slots__ = ('require_colons', 'managed', 'id', 'name', 'roles', 'guild', '_state')
|
||||||
|
|
||||||
def __init__(self, *, guild, state, data):
|
def __init__(self, *, guild, state, data):
|
||||||
self.guild = guild
|
self.guild = guild
|
||||||
|
@ -70,7 +70,7 @@ class ConnectionState:
|
|||||||
def clear(self):
|
def clear(self):
|
||||||
self.user = None
|
self.user = None
|
||||||
self._users = weakref.WeakValueDictionary()
|
self._users = weakref.WeakValueDictionary()
|
||||||
self._emojis = weakref.WeakValueDictionary()
|
self._emojis = {}
|
||||||
self._calls = {}
|
self._calls = {}
|
||||||
self._guilds = {}
|
self._guilds = {}
|
||||||
self._voice_clients = {}
|
self._voice_clients = {}
|
||||||
@ -157,6 +157,11 @@ class ConnectionState:
|
|||||||
def _remove_guild(self, guild):
|
def _remove_guild(self, guild):
|
||||||
self._guilds.pop(guild.id, None)
|
self._guilds.pop(guild.id, None)
|
||||||
|
|
||||||
|
for emoji in guild.emojis:
|
||||||
|
self._emojis.pop(emoji.id, None)
|
||||||
|
|
||||||
|
del guild
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def emojis(self):
|
def emojis(self):
|
||||||
return list(self._emojis.values())
|
return list(self._emojis.values())
|
||||||
@ -249,6 +254,7 @@ class ConnectionState:
|
|||||||
|
|
||||||
def parse_ready(self, data):
|
def parse_ready(self, data):
|
||||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
||||||
|
self.clear()
|
||||||
self.user = ClientUser(state=self, data=data['user'])
|
self.user = ClientUser(state=self, data=data['user'])
|
||||||
|
|
||||||
guilds = self._ready_state.guilds
|
guilds = self._ready_state.guilds
|
||||||
@ -760,7 +766,6 @@ class ConnectionState:
|
|||||||
class AutoShardedConnectionState(ConnectionState):
|
class AutoShardedConnectionState(ConnectionState):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
|
||||||
self._ready_task = None
|
self._ready_task = None
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -817,6 +822,7 @@ class AutoShardedConnectionState(ConnectionState):
|
|||||||
def parse_ready(self, data):
|
def parse_ready(self, data):
|
||||||
if not hasattr(self, '_ready_state'):
|
if not hasattr(self, '_ready_state'):
|
||||||
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
self._ready_state = ReadyState(launch=asyncio.Event(), guilds=[])
|
||||||
|
self.clear()
|
||||||
|
|
||||||
self.user = ClientUser(state=self, data=data['user'])
|
self.user = ClientUser(state=self, data=data['user'])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user