perf(database): scope listSnapshot table reads to current company
Add explicit LIMIT to all hot-path tables in listSnapshot regardless of companyId, raise cross-company caps from 500/250 to 2000/1000 so dashboard no longer truncates silently at 500. Add migration 28 with composite indexes covering snapshot WHERE/ORDER BY columns: tasks(company_id, created_at|updated_at), approvals(company_id, created_at), task_comments(company_id, created_at), documents(company_id, updated_at), meetings(company_id, scheduled_at), sprints(company_id, start_date), runs(agent_id, created_at), cost_entries(agent_id, created_at), activity(company_id, actor, action), tasks(company_id, assignee_agent_id, status). Indexes match exact ORDER BY direction so SQLite can satisfy reads via index scan without temp sort.
This commit is contained in:
1 parent
e2253b92fa
commit
47731f61a0
2 files changed
+21
-7
No files matched your search
@@ -407,6 +407,20 @@ export function runMigrations(
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
version: 28, name: "add_snapshot_hot_path_indexes",
|
||||
sql: `CREATE INDEX IF NOT EXISTS idx_tasks_company_created_at ON tasks(company_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_tasks_company_updated_at ON tasks(company_id, updated_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_approvals_company_created_at ON approvals(company_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_task_comments_company_created_at ON task_comments(company_id, created_at);
|
||||
CREATE INDEX IF NOT EXISTS idx_documents_company_updated_at ON documents(company_id, updated_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_meetings_company_scheduled_at ON meetings(company_id, scheduled_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_sprints_company_start_date ON sprints(company_id, start_date DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_runs_agent_created_at ON runs(agent_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_cost_entries_agent_created_at ON cost_entries(agent_id, created_at DESC);
|
||||
CREATE INDEX IF NOT EXISTS idx_activity_company_actor_action ON activity(company_id, actor, action);
|
||||
CREATE INDEX IF NOT EXISTS idx_tasks_company_assignee_status ON tasks(company_id, assignee_agent_id, status)`,
|
||||
},
|
||||
];
|
||||
|
||||
for (const migration of migrations) {
|
||||
|
||||
Reference in new issue
Block a user