async def save(client, dbFileName, message): accounts = utilities.unpackAccounts(message["accounts"]) packages = utilities.unpackPackages(message["packages"]) print("packages before ", message["packages"]) print("packages after ", packages) successList, failedList = database.save(dbFileName, accounts, packages) print("successList ", successList) await messages.respond( client, message, { "successful": utilities.packPackages(successList, set(["data"])), "failed": utilities.packPackages(failedList, set(["data"])) }) changedAccountIds = set([package["accountId"] for package in successList]) print("changedAccountIds1 ", changedAccountIds) print("activeClients ", connections.activeClients()) clients2accountIds = connections.getClients(changedAccountIds) print("changedAccountIds2.5 ", clients2accountIds) clients2accountIds.pop(client, None) print("changedAccountIds2 ", clients2accountIds) for otherClient, accountIds in clients2accountIds.items(): accountIds = list(accountIds) print("accountIds ", accountIds) await messages.send(otherClient, 'packages changed', {'accountIds': utilities.packBlobs(accountIds)})
async def save(client, dbFileName, message): accounts = utilities.unpackAccounts(message["accounts"]) packages = utilities.unpackPackages(message["packages"]) database.save(dbFileName, accounts, packages) successful = [ entity["entity"] for entity in packages if entity["status"] == "success" ] print("successful ", successful) await messages.respond( client, message, { "packages": [{ "entity": utilities.packPackages([entity["entity"]])[0], **(utilities.packEntities([entity])[0]) } for entity in packages] }) changedUsernames = set([package["username"] for package in successful]) clients2usernames = connections.getClients(changedUsernames) for otherClient, usernames in clients2usernames.items(): usernames = list(usernames) await messages.send(otherClient, 'packages changed', {'usernames': usernames})
async def get(client, dbFileName, message): accounts = utilities.unpackAccounts(message["accounts"]) packages, failedAccounts = database.get(dbFileName, accounts) await messages.respond(client, message, { 'packages': utilities.packPackages(packages, set(["_id"])), "failed": utilities.packAccounts(failedAccounts) })
async def save(client, dbFileName, message): accounts = utilities.unpackAccounts(message["accounts"]) packages = utilities.unpackPackages(message["packages"]) successList, failedList = database.save(dbFileName, accounts, packages) await messages.respond(client, message, { "successful" : utilities.packPackages(successList, set(["data"])), "failed" : utilities.packPackages(failedList, set(["data"])) }) changedAccountIds = set([package["accountId"] for package in successList]) clients2accountIds = connections.getClients(changedAccountIds) for otherClient, accountIds in clients2accountIds.items(): accountIds = list(accountIds) await messages.send(otherClient, 'packages changed', { 'accountIds': utilities.packBlobs(accountIds) })