修复get_latest_record_timestamp查询错误的表

问题:
- 查询ocr_staging表的timestamp字段,但该表没有timestamp字段
- 报错:no such column: timestamp

修复:
- 改为查询user_messages表的created_at字段(入库时间)
- 使用ensure_user_messages_table确保表存在
This commit is contained in:
youpaishidifu
2026-09-02 22:47:13 +08:00
parent 341a8f81fe
commit a6d7d5f083
+5 -4
View File
@@ -966,17 +966,18 @@ class MessageHistory:
conn.close() conn.close()
def get_latest_record_timestamp(self, platform: str) -> Optional[datetime]: def get_latest_record_timestamp(self, platform: str) -> Optional[datetime]:
"""获取该平台最近一条记录的时间戳(用于第二关判断)""" """获取该平台最近一条记录的入库时间(用于第二关判断)"""
self._ensure_ocr_staging_table() # ⭐ Task #1686: 查询 user_messages 表的 created_at 字段(入库时间)
self._ensure_user_messages_table()
conn = self._get_conn() conn = self._get_conn()
try: try:
cursor = conn.execute( cursor = conn.execute(
"SELECT timestamp FROM ocr_staging WHERE platform=? ORDER BY timestamp DESC LIMIT 1", "SELECT created_at FROM user_messages WHERE platform=? ORDER BY created_at DESC LIMIT 1",
(platform,) (platform,)
) )
row = cursor.fetchone() row = cursor.fetchone()
if row: if row:
# timestamp 字段格式为 "YYYY-MM-DD HH:MM:SS" # created_at 字段格式为 "YYYY-MM-DD HH:MM:SS"
try: try:
return datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S") return datetime.strptime(row[0], "%Y-%m-%d %H:%M:%S")
except (ValueError, TypeError): except (ValueError, TypeError):