diff options
Diffstat (limited to 'makima/src/db')
| -rw-r--r-- | makima/src/db/repository.rs | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/makima/src/db/repository.rs b/makima/src/db/repository.rs index 8923f97..e288eba 100644 --- a/makima/src/db/repository.rs +++ b/makima/src/db/repository.rs @@ -4993,11 +4993,20 @@ pub async fn list_directives_for_owner( d.id, d.owner_id, d.title, d.goal, d.status, d.repository_url, d.orchestrator_task_id, d.pr_url, d.completion_task_id, d.version, d.created_at, d.updated_at, - COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id), 0) as total_steps, - COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id AND status = 'completed'), 0) as completed_steps, - COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id AND status = 'running'), 0) as running_steps, - COALESCE((SELECT COUNT(*) FROM directive_steps WHERE directive_id = d.id AND status = 'failed'), 0) as failed_steps + COALESCE(s.total_steps, 0) as total_steps, + COALESCE(s.completed_steps, 0) as completed_steps, + COALESCE(s.running_steps, 0) as running_steps, + COALESCE(s.failed_steps, 0) as failed_steps FROM directives d + LEFT JOIN LATERAL ( + SELECT + COUNT(*) as total_steps, + COUNT(*) FILTER (WHERE status = 'completed') as completed_steps, + COUNT(*) FILTER (WHERE status = 'running') as running_steps, + COUNT(*) FILTER (WHERE status = 'failed') as failed_steps + FROM directive_steps + WHERE directive_id = d.id + ) s ON true WHERE d.owner_id = $1 ORDER BY d.created_at DESC "#, |
