src/lib/routers/queue.ts iterates over every epic in a for-loop, then issues two more queries inside each iteration (one for features, one for sub-tasks per feature), plus a per-feature isFeatureBlocked() call. For a project with 10 epics × 5 features × 5 sub-tasks = 151+ DB round-trips per single API call.
Category: database
File: src/lib/routers/queue.ts
Recommendation: Replace the nested for-loop with a single SQL JOIN across epics → features → sub_tasks with status='pending', augmented by a CTE or subquery for the blocker check. The isFeatureBlocked() function (in pipeline-helpers.ts) deserialises blockedByFeatureIds JSONB and queries features — batch this with an IN-clause after fetching all features at once.
Estimated Improvement: Reduces from O(epics × features) queries to 2-3 queries; 10-50× faster for typical project sizes