fix(chat/wechat): messages order by created_at,id (sub-second DATETIME(3)); container+MySQL TZ->Asia/Shanghai; correct UTC timestamps to CST; rebuild WeXin Bot history

This commit is contained in:
qyyfw committed 2026-07-10 10:50:06 +08:00
1 parent 7b7871a14d
commit 774f1648dc
2 files changed
+1351 -1348

No files matched your search

File diff suppressed because it is too large. Load diff
+6 -3
View File
@@ -17,7 +17,7 @@ import json
import random
import threading
import time
from datetime import datetime
from datetime import datetime, timedelta
from typing import Optional
import requests
@@ -310,8 +310,11 @@ def _mirror_to_ai_chat(user_id: str, user_content: str, assistant_content: str):
try:
db = SessionLocal()
cid = _get_or_create_wechat_conv(db, user_id)
_append_ai_message(db, cid, "user", user_content)
_append_ai_message(db, cid, "assistant", assistant_content)
now = datetime.now()
_append_ai_message(db, cid, "user", user_content, created=now)
# assistant 比 user 晚 50ms,保证排序严格递增,避免同秒时 ORDER BY 乱序
_append_ai_message(db, cid, "assistant", assistant_content,
created=now + timedelta(milliseconds=50))
_execute_raw(db, text("UPDATE conversations SET updated_at=:u WHERE id=:id"),
{"u": datetime.now(), "id": cid})
except Exception: