users: fix some cross-scope inconsistency when dispatching

Closes #19.

 - dispatcher: remove dispatch_many_filter, add
    dispatch_many_filter_list
This commit is contained in:
Luna Mendes 2018-11-19 15:53:04 -03:00
parent e627d61fd0
commit 54120bce0c
2 changed files with 17 additions and 15 deletions

View File

@ -211,17 +211,15 @@ async def patch_me():
friend_ids = await app.user_storage.get_friend_ids(user_id)
session_ids.extend(
await app.dispatcher.dispatch_many_filter(
'guild', guild_ids,
lambda sess_id: sess_id not in session_ids,
await app.dispatcher.dispatch_many_filter_list(
'guild', guild_ids, session_ids,
'USER_UPDATE', public_user
)
)
session_ids.extend(
await app.dispatcher.dispatch_many_filter(
'friend', friend_ids,
lambda sess_id: sess_id not in session_ids,
await app.dispatcher.dispatch_many_filter_list(
'friend', friend_ids, session_ids,
'USER_UPDATE', public_user
)
)

View File

@ -114,20 +114,24 @@ class EventDispatcher:
key = backend.KEY_TYPE(key)
return await backend.dispatch_filter(key, func, *args)
async def dispatch_many_filter(self, backend_str, keys: List[Any],
func, *args) -> List[str]:
"""Call the dispatch_filter method to many keys.
async def dispatch_many_filter_list(self, backend_str: str,
keys: List[Any], sess_list: List[str],
*args):
"""Make a "unique" dispatch given a list of session ids.
Not all backends will handle this function.
This only works for backends that have a dispatch_filter
handler and return session id lists in their dispatch
results.
"""
res = []
for key in keys:
res.extend(
await self.dispatch_filter(backend_str, key, func, *args)
sess_list.extend(
await self.dispatch_filter(
backend_str, key,
lambda sess_id: sess_id not in sess_list,
*args)
)
return res
return sess_list
async def reset(self, backend_str: str, key: Any):
"""Reset the bucket in the given backend."""