sync update from LAN repo (source dhk-1 @ 3b1ec5b4)
This commit is contained in:
1 parent
da6521b6cb
commit
264e2200d6
995 files changed
+148105
-13399
No files matched your search
+20
@@ -7,6 +7,7 @@ from datetime import UTC, datetime
|
||||
from typing import Any
|
||||
|
||||
from sqlalchemy import delete, func, select, update
|
||||
from sqlalchemy.orm import aliased
|
||||
from sqlalchemy.exc import IntegrityError
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
@@ -60,6 +61,25 @@ class PositionRepository(PositionStore):
|
||||
counts = await self._member_counts(session, [position_id])
|
||||
return _position_to_dict(row, counts.get(position_id, 0))
|
||||
|
||||
async def get_effective_position(self, user_id: str) -> dict[str, Any] | None:
|
||||
"""Resolve the assigned/default position with one narrow indexed query."""
|
||||
assigned = aliased(PositionRow)
|
||||
default = aliased(PositionRow)
|
||||
stmt = (
|
||||
select(assigned, default)
|
||||
.select_from(UserRow)
|
||||
.outerjoin(assigned, UserRow.position_id == assigned.id)
|
||||
.outerjoin(default, default.is_default.is_(True))
|
||||
.where(UserRow.id == user_id)
|
||||
.limit(1)
|
||||
)
|
||||
async with self._sf() as session:
|
||||
row = (await session.execute(stmt)).first()
|
||||
if row is None:
|
||||
return None
|
||||
position = row[0] or row[1]
|
||||
return _position_to_dict(position, 0) if position is not None else None
|
||||
|
||||
async def create_position(self, data: dict[str, Any]) -> dict[str, Any]:
|
||||
now = datetime.now(UTC)
|
||||
is_default = bool(data.get("is_default"))
|
||||
|
||||
Reference in new issue
Block a user