mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-04 18:05:06 -04:00
Add type hints to synapse/storage/databases/main
(#11984)
This commit is contained in:
parent
99f6d79fe1
commit
7c82da27aa
7 changed files with 79 additions and 53 deletions
|
@ -204,25 +204,27 @@ class BasePresenceHandler(abc.ABC):
|
|||
Returns:
|
||||
dict: `user_id` -> `UserPresenceState`
|
||||
"""
|
||||
states = {
|
||||
user_id: self.user_to_current_state.get(user_id, None)
|
||||
for user_id in user_ids
|
||||
}
|
||||
states = {}
|
||||
missing = []
|
||||
for user_id in user_ids:
|
||||
state = self.user_to_current_state.get(user_id, None)
|
||||
if state:
|
||||
states[user_id] = state
|
||||
else:
|
||||
missing.append(user_id)
|
||||
|
||||
missing = [user_id for user_id, state in states.items() if not state]
|
||||
if missing:
|
||||
# There are things not in our in memory cache. Lets pull them out of
|
||||
# the database.
|
||||
res = await self.store.get_presence_for_users(missing)
|
||||
states.update(res)
|
||||
|
||||
missing = [user_id for user_id, state in states.items() if not state]
|
||||
if missing:
|
||||
new = {
|
||||
user_id: UserPresenceState.default(user_id) for user_id in missing
|
||||
}
|
||||
states.update(new)
|
||||
self.user_to_current_state.update(new)
|
||||
for user_id in missing:
|
||||
# if user has no state in database, create the state
|
||||
if not res.get(user_id, None):
|
||||
new_state = UserPresenceState.default(user_id)
|
||||
states[user_id] = new_state
|
||||
self.user_to_current_state[user_id] = new_state
|
||||
|
||||
return states
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue