Moved sorting back to the get_accounts

This commit is contained in:
StNicolay 2023-01-05 13:03:44 +03:00
parent 4954f39a91
commit 9f64305050
2 changed files with 6 additions and 3 deletions

View File

@ -540,7 +540,6 @@ async def _export2(
) )
tasks.append(loop.run_in_executor(pool, function)) tasks.append(loop.run_in_executor(pool, function))
accounts = await asyncio.gather(*tasks) accounts = await asyncio.gather(*tasks)
accounts.sort(key=lambda account: account.name)
json_io = accounts_to_json(accounts) json_io = accounts_to_json(accounts)
await bot.send_document( await bot.send_document(
mes.chat.id, mes.chat.id,

View File

@ -36,9 +36,13 @@ def get_account_names(
def get_accounts(engine: Engine, user_id: int) -> list[models.Account]: def get_accounts(engine: Engine, user_id: int) -> list[models.Account]:
"""Returns a list of accounts of a user""" """Returns a list of accounts of a user"""
statement = sqlmodel.select(models.Account).where( statement = (
sqlmodel.select(models.Account)
.where(
models.Account.user_id == user_id, models.Account.user_id == user_id,
) )
.order_by(models.Account.name)
)
with sqlmodel.Session(engine) as session: with sqlmodel.Session(engine) as session:
result = session.exec(statement).fetchall() result = session.exec(statement).fetchall()
return result return result