refactor(api): staff-chat-stats 确定性排序 + last_is_send=None 分支测试 + 类型标注

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
浅念
2026-08-07 18:37:26 +08:00
parent d2b2c0f5b3
commit 628659b849
2 changed files with 46 additions and 1 deletions
@@ -36,7 +36,7 @@ def _private_window(msg, owner: str, start: int, end: int):
]
async def _aggregate(session: AsyncSession, owner: str, start: int, end: int):
async def _aggregate(session: AsyncSession, owner: str, start: int, end: int) -> tuple[list, dict[str, bool | None]]:
"""返回 [(talker_id, send, recv, interaction_days, last_time)] + last_is_send map。"""
# 跨库日期提取:从 ms-epoch 取日期。镜像 repos.py 方言检测。
dialect = session.bind.name # 镜像 app/storage/repos.py(.name 等价 .dialect.name)
@@ -56,6 +56,7 @@ async def _aggregate(session: AsyncSession, owner: str, start: int, end: int):
)
.where(*base)
.group_by(Message.talker_id)
.order_by(Message.talker_id)
)
agg_rows = (await session.execute(agg_stmt)).all()