sync update from LAN repo (source master @ ca48c4ec)

This commit is contained in:
gozeros committed 2026-11-05 10:53:54 +08:00
1 parent 8bc8b0e082
commit ea9dcff9c0
873 files changed
+107866 -14011

No files matched your search

@@ -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"))