perf: Optimize dashboard queries for faster load times
- Use pg_stat for approximate product count (instant vs full scan) - LIMIT on DISTINCT queries for brand/category counts - Single combined query (reduces round trips) - Add index on store_product_snapshots.captured_at - Add index on worker_tasks.worker_id and created_at 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
11
backend/migrations/097_worker_tasks_worker_id_index.sql
Normal file
11
backend/migrations/097_worker_tasks_worker_id_index.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Migration: Add indexes for dashboard performance
|
||||
-- Speeds up the tasks listing query with ORDER BY and JOIN
|
||||
|
||||
-- Index for JOIN with worker_registry
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_worker_tasks_worker_id
|
||||
ON worker_tasks(worker_id)
|
||||
WHERE worker_id IS NOT NULL;
|
||||
|
||||
-- Index for ORDER BY created_at DESC (dashboard listing)
|
||||
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_worker_tasks_created_at_desc
|
||||
ON worker_tasks(created_at DESC);
|
||||
Reference in New Issue
Block a user