"""Display names for a set of accounts in one query.""" from collections.abc import Iterable from uuid import UUID from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.modules.accounts.models import Account async def account_names(session: AsyncSession, ids: Iterable[UUID | None]) -> dict[UUID, str | None]: wanted = {i for i in ids if i} if not wanted: return {} rows = await session.execute(select(Account.id, Account.name).where(Account.id.in_(wanted))) return {i: n for i, n in rows}