pubsub.lazy_guild: better method to remove member

This commit is contained in:
Luna Mendes 2018-11-19 04:10:18 -03:00
parent 994c3eb640
commit 113ba3fb89
1 changed files with 19 additions and 6 deletions

View File

@ -875,15 +875,28 @@ class GuildMemberList:
return state.user_id != user_id return state.user_id != user_id
# for now, remove any of the users' subscribed states # for now, remove any of the users' subscribed states
old_len = len(self.state) state_keys = self.state.keys()
self.state = set(filter( for session_id in state_keys:
is_valid_state, state = self.get_state(session_id)
self.state
))
# if unknown state, remove from the subscriber list
if state is None:
self.state.pop(session_id)
# if we aren't talking about the state the user
# being removed is subscribed to, ignore
if state.user_id != user_id:
continue
# state.user_id == user_id being removed,
# so we remove it.
self.state.pop(session_id)
old_len = len(state_keys)
removed = old_len - len(self.state) removed = old_len - len(self.state)
log.info('removed {} states due to remove_member {}',
log.info('lazy: removed {} states due to remove_member {}',
removed, user_id) removed, user_id)
# then clean anything on the internal member list # then clean anything on the internal member list