* [perf] Refactor to use index in query to improve performance.

This commit is contained in:
liugang
2025-08-06 15:22:14 +08:00
committed by tianshujie
parent 3e4cb894f4
commit 419aabfdaf
+7 -2
View File
@@ -2101,11 +2101,16 @@ class taskModel extends model
*/
public function getAllChildId(int $taskID, bool $includeSelf = true): array
{
if(!$taskID) return [];
$task = $this->fetchByID($taskID);
if(!$task) return [];
return $this->dao->select('id')->from(TABLE_TASK)
->where('path')->like("%,$taskID,%")
->where('path')->like($task->path . '%') // 去除左侧的模糊查询以利用索引提高性能。Remove the left fuzzy query to use index to improve performance.
->andWhere('deleted')->eq(0)
->beginIF(!$includeSelf)->andWhere('id')->ne($taskID)->fi()
->fetchPairs('id');
->fetchPairs();
}
/**