fix: 全面防御性编程确保所有数据库表存在,解决多个no such table错误 (Task #1658)
This commit is contained in:
+15
@@ -492,6 +492,9 @@ class MessageHistory:
|
|||||||
if not content or not content.strip():
|
if not content or not content.strip():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
# 防御性编程:确保表存在
|
||||||
|
self._ensure_user_messages_table()
|
||||||
|
|
||||||
cleaned_current = self._clean_text_for_dedup(content)
|
cleaned_current = self._clean_text_for_dedup(content)
|
||||||
if len(cleaned_current) < 2: # 太短无法比对
|
if len(cleaned_current) < 2: # 太短无法比对
|
||||||
return False
|
return False
|
||||||
@@ -661,6 +664,9 @@ class MessageHistory:
|
|||||||
|
|
||||||
user_msg_time: 用户消息的时间戳(Unix时间),如果晚于最后bot回复时间,则视为新消息不跳过
|
user_msg_time: 用户消息的时间戳(Unix时间),如果晚于最后bot回复时间,则视为新消息不跳过
|
||||||
"""
|
"""
|
||||||
|
# 防御性编程:确保表存在
|
||||||
|
self._ensure_bot_messages_table()
|
||||||
|
|
||||||
content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest()
|
content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest()
|
||||||
conn = self._get_conn()
|
conn = self._get_conn()
|
||||||
try:
|
try:
|
||||||
@@ -722,6 +728,9 @@ class MessageHistory:
|
|||||||
|
|
||||||
def last_bot_reply_time(self, platform: str) -> float:
|
def last_bot_reply_time(self, platform: str) -> float:
|
||||||
"""获取该平台最近一次bot回复的时间戳(Unix时间)"""
|
"""获取该平台最近一次bot回复的时间戳(Unix时间)"""
|
||||||
|
# 防御性编程:确保表存在
|
||||||
|
self._ensure_bot_messages_table()
|
||||||
|
|
||||||
conn = self._get_conn()
|
conn = self._get_conn()
|
||||||
try:
|
try:
|
||||||
cursor = conn.execute(
|
cursor = conn.execute(
|
||||||
@@ -746,6 +755,9 @@ class MessageHistory:
|
|||||||
Args:
|
Args:
|
||||||
within_minutes: 只返回最近N分钟内的回复,None表示不过滤时间
|
within_minutes: 只返回最近N分钟内的回复,None表示不过滤时间
|
||||||
"""
|
"""
|
||||||
|
# 防御性编程:确保表存在
|
||||||
|
self._ensure_bot_messages_table()
|
||||||
|
|
||||||
conn = self._get_conn()
|
conn = self._get_conn()
|
||||||
try:
|
try:
|
||||||
if within_minutes is not None and within_minutes > 0:
|
if within_minutes is not None and within_minutes > 0:
|
||||||
@@ -821,6 +833,9 @@ class MessageHistory:
|
|||||||
|
|
||||||
def has_ocr_message_record(self, platform: str, content: str) -> bool:
|
def has_ocr_message_record(self, platform: str, content: str) -> bool:
|
||||||
"""检查OCR暂存表中是否已存在该消息的记录(用于时间戳新鲜度评分逻辑)"""
|
"""检查OCR暂存表中是否已存在该消息的记录(用于时间戳新鲜度评分逻辑)"""
|
||||||
|
# 防御性编程:确保表存在
|
||||||
|
self._ensure_ocr_staging_table()
|
||||||
|
|
||||||
content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest()
|
content_hash = hashlib.md5(content.strip().encode('utf-8')).hexdigest()
|
||||||
conn = self._get_conn()
|
conn = self._get_conn()
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user