fix(express): 修复异步会话中错误的删除操作

在 `ExpressionLearner` 的 `decay` 方法中,`session.delete(expr)` 操作是同步的,但在异步会话(`AsyncSession`)上下文中应该使用 `await`。此更改修复了该问题,确保表达式能被正确地异步删除。
This commit is contained in:
minecraft1024a
2025-10-04 12:07:39 +08:00
committed by Windpicker-owo
parent 8822bcd3ef
commit 87ce36b62b

View File

@@ -240,7 +240,7 @@ class ExpressionLearner:
if new_count <= 0.01: if new_count <= 0.01:
# 如果count太小删除这个表达方式 # 如果count太小删除这个表达方式
session.delete(expr) await session.delete(expr)
await session.commit() await session.commit()
deleted_count += 1 deleted_count += 1
else: else:
@@ -502,16 +502,29 @@ class ExpressionLearnerManager:
return return
if os.path.exists(done_flag): if os.path.exists(done_flag):
logger.info("表达方式JSON已迁移无需重复迁移。") logger.debug("表达方式JSON已迁移无需重复迁移。")
else: return
logger.info("开始迁移表达方式JSON到数据库...")
migrated_count = 0
for type in ["learnt_style", "learnt_grammar"]: logger.info("开始迁移表达方式JSON到数据库...")
type_str = "style" if type == "learnt_style" else "grammar" migrated_count = 0
type_dir = os.path.join(base_dir, type)
if not os.path.exists(type_dir): for type in ["learnt_style", "learnt_grammar"]:
logger.debug(f"目录不存在,跳过: {type_dir}") type_str = "style" if type == "learnt_style" else "grammar"
type_dir = os.path.join(base_dir, type)
if not os.path.exists(type_dir):
logger.debug(f"目录不存在,跳过: {type_dir}")
continue
try:
chat_ids = os.listdir(type_dir)
logger.debug(f"{type_dir} 中找到 {len(chat_ids)} 个聊天ID目录")
except Exception as e:
logger.error(f"读取目录失败 {type_dir}: {e}")
continue
for chat_id in chat_ids:
expr_file = os.path.join(type_dir, chat_id, "expressions.json")
if not os.path.exists(expr_file):
continue continue
try: try: