Fix user cache acting incorrectly with evictions
The first issue involved copied users which would lead to user updates causing faster evictions of the cache than was expected. The second issue involved users that weren't bound to an internal lifetime eviction policy. These users would not get evicted. For example, a user without mutual guilds or being part of the internal cache in general (messages, DMs) would never end up being evicted for some strange reason. To handle this case, store_user would get a counterpart named create_user which would create a user without potentially storing them in the cache. That way only users with a bound lifetime within the library would be stored.
This commit is contained in:
@ -178,7 +178,7 @@ class ConnectionState:
|
||||
self._intents = intents
|
||||
|
||||
if not intents.members or cache_flags._empty:
|
||||
self.store_user = self.store_user_no_intents
|
||||
self.store_user = self.create_user
|
||||
self.deref_user = self.deref_user_no_intents
|
||||
|
||||
self.parsers = parsers = {}
|
||||
@ -284,7 +284,7 @@ class ConnectionState:
|
||||
def deref_user(self, user_id):
|
||||
self._users.pop(user_id, None)
|
||||
|
||||
def store_user_no_intents(self, data):
|
||||
def create_user(self, data):
|
||||
return User(state=self, data=data)
|
||||
|
||||
def deref_user_no_intents(self, user_id):
|
||||
|
Reference in New Issue
Block a user