From 65e1bcf9d8941fa6ac14f3f6a0bd571fb03106f7 Mon Sep 17 00:00:00 2001 From: cfdaily Date: Mon, 18 May 2026 12:08:26 +0800 Subject: [PATCH] auto-sync: 2026-05-18 12:08:26 --- src/daemon/ticker.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/daemon/ticker.py b/src/daemon/ticker.py index bb06c4c..448b5e5 100644 --- a/src/daemon/ticker.py +++ b/src/daemon/ticker.py @@ -250,28 +250,23 @@ class Ticker: def _refresh_parent_statuses(self, db_path: Path) -> List[str]: """全量扫描有子 Task 的父 Task,刷新聚合状态 - 跳过手动状态(cancelled)的父 Task。 + 跳过手动状态(cancelled)的父 Task。使用单连接批量处理。 """ queries = Queries(db_path) refreshed: List[str] = [] - # 找出所有有子 Task 的父 Task ID conn = get_connection(db_path) try: + # 找出所有有子 Task 的父 Task ID parent_rows = conn.execute( "SELECT DISTINCT parent_task FROM tasks WHERE parent_task IS NOT NULL" ).fetchall() parent_ids = [r["parent_task"] for r in parent_rows] - finally: - conn.close() - for pid in parent_ids: - computed = queries.compute_parent_status(pid) - if computed is None: - continue - # 直接更新(跳过手动状态已在 compute 里判断) - conn = get_connection(db_path) - try: + for pid in parent_ids: + computed = queries.compute_parent_status(pid) + if computed is None: + continue parent = conn.execute( "SELECT status FROM tasks WHERE id=?", (pid,) ).fetchone() @@ -280,9 +275,14 @@ class Ticker: "UPDATE tasks SET status=?, updated_at=datetime('now') WHERE id=?", (computed, pid), ) - conn.commit() refreshed.append(pid) logger.info("Parent %s status aggregated: → %s", pid, computed) + + if refreshed: + conn.commit() + finally: + conn.close() + logger.info("Parent %s status aggregated: → %s", pid, computed) finally: conn.close()