_export2 no longer blocks event loop during decryption
Removed sorting in get_all_accounts Removed decrypt_multiple function because it is no longer used Now running decrytion of accounts in ProcessPoolExecutor
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import asyncio
|
||||
import functools
|
||||
import gc
|
||||
from concurrent.futures import ProcessPoolExecutor
|
||||
|
||||
import telebot
|
||||
from sqlalchemy.future import Engine
|
||||
@ -534,7 +536,16 @@ async def _export2(
|
||||
)
|
||||
|
||||
accounts = database.get.get_all_accounts(engine, mes.from_user.id)
|
||||
accounts = encryption.other_accounts.decrypt_multiple(accounts, text)
|
||||
with ProcessPoolExecutor() as pool:
|
||||
loop = asyncio.get_running_loop()
|
||||
tasks = []
|
||||
for account in accounts:
|
||||
function = functools.partial(
|
||||
encryption.other_accounts.decrypt, account, text
|
||||
)
|
||||
tasks.append(loop.run_in_executor(pool, function))
|
||||
accounts = await asyncio.gather(*tasks)
|
||||
accounts.sort(key=lambda account: account.name)
|
||||
json_io = accounts_to_json(accounts)
|
||||
await bot.send_document(
|
||||
mes.chat.id,
|
||||
|
Reference in New Issue
Block a user