feat: 更新章节查询逻辑以仅返回活跃章节

- 修改章节查询语句,确保只查找标记为活跃的章节,避免更新已清除的章节。
- 相关注释更新以反映新的逻辑,提升代码可读性。
This commit is contained in:
penghanyuan
2026-02-14 11:16:09 +01:00
parent 39736a2ae2
commit b46289bb1e

View File

@@ -212,10 +212,11 @@ def process_memoir_segments(self, user_id: str, segment_ids: List[str]):
combined_text = "\n\n".join(segment_texts)
source_ids = [seg.id for seg in stage_segments]
# 查找或创建章节
# 查找 active 章节(被清除的章节不继续更新,而是创建新的)
stmt_chapter = select(Chapter).where(
Chapter.user_id == user_id,
Chapter.category == stage,
Chapter.is_active == True,
)
result_chapter = db.execute(stmt_chapter)
chapter = result_chapter.scalar_one_or_none()
@@ -340,10 +341,11 @@ def generate_chapter_content(self, user_id: str, stage: str, new_content: str):
try:
llm = llm_service.get_llm()
# 查找章节
# 查找 active 章节(被清除的章节不继续更新,而是创建新的)
stmt = select(Chapter).where(
Chapter.user_id == user_id,
Chapter.category == stage,
Chapter.is_active == True,
)
result = db.execute(stmt)
chapter = result.scalar_one_or_none()