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:
1 parent
7b7871a14d
commit
774f1648dc
2 files changed
+1351
-1348
No files matched your search
+1345
-1345
File diff suppressed because it is too large.
Load diff
@@ -17,7 +17,7 @@ import json
|
|||||||
import random
|
import random
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
@@ -310,8 +310,11 @@ def _mirror_to_ai_chat(user_id: str, user_content: str, assistant_content: str):
|
|||||||
try:
|
try:
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
cid = _get_or_create_wechat_conv(db, user_id)
|
cid = _get_or_create_wechat_conv(db, user_id)
|
||||||
_append_ai_message(db, cid, "user", user_content)
|
now = datetime.now()
|
||||||
_append_ai_message(db, cid, "assistant", assistant_content)
|
_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"),
|
_execute_raw(db, text("UPDATE conversations SET updated_at=:u WHERE id=:id"),
|
||||||
{"u": datetime.now(), "id": cid})
|
{"u": datetime.now(), "id": cid})
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in new issue
Block a user