refactor(db): 将数据库操作异步化
- 将所有 session.add() 改为 await session.add() - 将所有 session.commit() 改为 await session.commit() - 将 session.refresh() 改为 await session.refresh()
This commit is contained in:
@@ -42,7 +42,7 @@ async def add_new_plans(plans: List[str], month: str):
|
||||
new_plan_objects = [
|
||||
MonthlyPlan(plan_text=plan, target_month=month, status="active") for plan in plans_to_add
|
||||
]
|
||||
session.add_all(new_plan_objects)
|
||||
await session.add_all(new_plan_objects)
|
||||
await session.commit()
|
||||
|
||||
logger.info(f"成功向数据库添加了 {len(new_plan_objects)} 条 {month} 的月度计划。")
|
||||
|
||||
@@ -128,7 +128,7 @@ class ScheduleManager:
|
||||
existing_schedule.updated_at = datetime.now()
|
||||
else:
|
||||
new_schedule = Schedule(date=date_str, schedule_data=schedule_json)
|
||||
session.add(new_schedule)
|
||||
await session.add(new_schedule)
|
||||
await session.commit()
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user