#525 [API/Perf] N+1 query in queue analytics endpoint

closed critical Created 2025-12-17 15:00 · Updated 2025-12-17 15:12

Description

Edit
**File:** api/blueprints/v1/analytics.py:63-68 **Problem:** For N queues, executes N+1 queries (1 for queue list + 1 per queue). With 50 queues: 51 database round-trips. **Current:** ```python for row in queue_rows: queue_name = row['queue_name'] metrics = await get_queue_metrics(queue_name, tenant_id) # QUERY IN LOOP ``` **Fix:** Single query with GROUP BY: ```sql SELECT workflow_name as queue_name, COUNT(*) FILTER (WHERE status = 'pending') as pending_count, COUNT(*) FILTER (WHERE status = 'running') as running_count, ... FROM workflow_run WHERE tenant_id = %s GROUP BY workflow_name ``` **Impact:** 50x speedup for 50 queues (50ms → 1ms).

Comments

Loading comments...

Context

Loading context...

Audit History

View All
Loading audit history...