ui: Don't load pan users from the db, pass them over the queue.

This commit is contained in:
Damir Jelić 2019-06-19 15:54:58 +02:00
parent dae6084919
commit 62d0e5607e
3 changed files with 18 additions and 9 deletions

View File

@ -91,6 +91,8 @@ class ProxyDaemon:
database_name = "pan.db"
def __attrs_post_init__(self):
loop = asyncio.get_event_loop()
self.homeserver_url = self.homeserver.geturl()
self.hostname = self.homeserver.hostname
self.store = PanStore(self.data_dir)
@ -130,6 +132,12 @@ class ProxyDaemon:
pan_client.load_store()
self.pan_clients[user_id] = pan_client
loop.create_task(
self.send_queue.put(
UpdateUsersMessage(self.name, user_id, pan_client.device_id)
)
)
pan_client.start_loop()
async def _find_client(self, access_token):
@ -542,7 +550,9 @@ class ProxyDaemon:
logger.info(f"Succesfully started new background sync client for " f"{user_id}")
await self.send_queue.put(UpdateUsersMessage())
await self.send_queue.put(
UpdateUsersMessage(self.name, user_id, pan_client.device_id)
)
self.pan_clients[user_id] = pan_client

View File

@ -54,7 +54,9 @@ class DaemonResponse(Message):
@attr.s
class UpdateUsersMessage(Message):
pass
server = attr.ib()
user_id = attr.ib()
device_id = attr.ib()
@attr.s

View File

@ -117,12 +117,10 @@ class Control:
self.store = store
self.queue = queue
self.id_counter = id_counter
self.users = defaultdict(list)
self.update_users()
self.users = defaultdict(set)
def update_users(self):
for server in self.server_list:
self.users[server.name] = self.store.load_users(server.name)
def update_users(self, message):
self.users[message.server].add((message.user_id, message.device_id))
@property
def message_id(self):
@ -369,7 +367,6 @@ class GlibT:
self.loop = None
self.store = PanStore(self.data_dir)
self.users = self.store.load_all_users()
id_counter = IdCounter()
@ -489,7 +486,7 @@ class GlibT:
self.device_if.update_devices()
elif isinstance(message, UpdateUsersMessage):
self.control_if.update_users()
self.control_if.update_users(message)
elif isinstance(message, UnverifiedDevicesSignal):
self.control_if.UnverifiedDevices(