perf(dashboard): index tasks.column/updatedAt and debounce detail fetches

Speeds up task-list load and interaction for projects with 100+ tasks.

- Migration 59 adds idxTasksColumn and idxTasksUpdatedAt; listTasks()
  filters by "column" on every board load and SSE/refresh paths sort by
  updatedAt, so each query was previously a full table scan plus a temp
  B-tree sort.
- Debounce handleEmbeddedOpenDetail in ListView so rapid keyboard/mouse
  navigation no longer fires a heavy /tasks/:id (log + comments) per
  selection; stale-target requests short-circuit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-05-03 01:06:18 -07:00
parent e392770be3
commit 9619cd102d
9 changed files with 86 additions and 32 deletions

View File

@@ -0,0 +1,10 @@
---
"@runfusion/fusion": patch
---
Speed up dashboard load and interaction for projects with 100+ tasks.
Two cheap fixes that together cover the dominant hot paths:
- **DB indexes on `tasks.column` and `tasks.updatedAt`** (migration 59 in `packages/core/src/db.ts`). `listTasks()` filters by `"column"` on every board load, and the SSE/refresh paths sort by `updatedAt`; neither column had an index, so each query did a full table scan plus a temp B-tree sort. With 100+ tasks this becomes the dominant cost on initial load.
- **Debounce embedded detail-pane fetches** (`packages/dashboard/app/components/ListView.tsx`). `handleEmbeddedOpenDetail` previously fired a full `fetchTaskDetail` (which pulls log + comments) synchronously on every selection change, so rapid keyboard/mouse navigation through a long list would issue a burst of heavy requests. Fetches are now debounced to 200 ms and stale-target requests short-circuit before hitting the server and before applying state.

View File

@@ -155,7 +155,7 @@ describe("Database", () => {
});
it("seeds schema version", () => {
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
});
it("seeds lastModified", () => {
@@ -178,7 +178,7 @@ describe("Database", () => {
it("is idempotent - calling init() twice does not fail", () => {
expect(() => db.init()).not.toThrow();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
});
it("does not overwrite existing config on re-init", () => {
@@ -899,7 +899,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 29 (includes v1→v2 through v26→v29)
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -924,11 +924,11 @@ describe("schema migrations", () => {
const db = new Database(fusionDir);
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
// Re-init should not fail
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
db.close();
});
@@ -963,7 +963,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
expect(cols.map((col) => col.name)).toContain("priority");
@@ -1004,7 +1004,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
const colNames = cols.map((col) => col.name);
@@ -1073,7 +1073,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
const colNames = cols.map((col) => col.name);
@@ -1176,7 +1176,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const cols = db.prepare("PRAGMA table_info(chat_messages)").all() as Array<{ name: string }>;
expect(cols.map((col) => col.name)).toContain("attachments");
@@ -1250,7 +1250,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'agentRatings'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "agentRatings" }]);
@@ -1274,7 +1274,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'mission_events'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "mission_events" }]);
@@ -1378,7 +1378,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 29
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -1847,7 +1847,7 @@ describe("createDatabase factory", () => {
const db = createDatabase(fusionDir);
db.init();
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
expect(db.getLastModified()).toBeGreaterThan(0);
db.close();

View File

@@ -871,7 +871,7 @@ describe("Migration: pre-33 DB upgrade", () => {
// Step 1: Create a fresh database at v33 (runs all migrations up to 33)
const db1 = createDatabase(legacyDir);
db1.init();
expect(db1.getSchemaVersion()).toBe(58);
expect(db1.getSchemaVersion()).toBe(59);
db1.close();
// Step 2: Manually downgrade to version 32 and drop insight tables
@@ -906,7 +906,7 @@ describe("Migration: pre-33 DB upgrade", () => {
expect(tableNamesBefore).not.toContain("project_insight_runs");
// Now run init — this triggers the v32→v33 migration
db3.init();
expect(db3.getSchemaVersion()).toBe(58);
expect(db3.getSchemaVersion()).toBe(59);
// Step 4: Verify insight tables exist after migration
const tablesAfter = db3.prepare(
@@ -937,12 +937,12 @@ describe("Migration: pre-33 DB upgrade", () => {
try {
const db1 = createDatabase(testDir);
db1.init();
expect(db1.getSchemaVersion()).toBe(58);
expect(db1.getSchemaVersion()).toBe(59);
db1.close();
const db2 = createDatabase(testDir);
expect(() => db2.init()).not.toThrow();
expect(db2.getSchemaVersion()).toBe(58);
expect(db2.getSchemaVersion()).toBe(59);
db2.close();
} finally {
rmSync(testDir, { recursive: true, force: true });

View File

@@ -2629,7 +2629,7 @@ describe("MissionStore", () => {
describe("Loop State & Validator Run Schema (v31)", () => {
it("schema version is 40 after migration", () => {
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
});
it("mission_features table has loop state columns", () => {

View File

@@ -742,7 +742,7 @@ describe("RoadmapStore", () => {
describe("schema version", () => {
it("schema version is 40 after init", () => {
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
});
});

View File

@@ -465,7 +465,7 @@ describe("Run Audit", () => {
});
it("schema version is bumped to 40", () => {
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
});
});
});

View File

@@ -51,7 +51,7 @@ describe("TaskStore task documents", () => {
expect(tableNames.has("task_documents")).toBe(true);
expect(tableNames.has("task_document_revisions")).toBe(true);
expect(db.getSchemaVersion()).toBe(58);
expect(db.getSchemaVersion()).toBe(59);
const index = db
.prepare(

View File

@@ -88,7 +88,7 @@ export function probeFts5(db: DatabaseSync): boolean {
// ── Schema Definition ────────────────────────────────────────────────
const SCHEMA_VERSION = 58;
const SCHEMA_VERSION = 59;
function normalizeTaskComments(
steeringComments: SteeringComment[] | undefined,
@@ -2246,6 +2246,17 @@ export class Database {
});
}
// Dashboard load performance for projects with 100+ tasks.
// listTasks() filters by "column" and the SSE/refresh paths sort by
// updatedAt; neither column had an index, so each board load did a
// full table scan + temp B-tree sort.
if (version < 59) {
this.applyMigration(59, () => {
this.db.exec(`CREATE INDEX IF NOT EXISTS idxTasksColumn ON tasks("column")`);
this.db.exec(`CREATE INDEX IF NOT EXISTS idxTasksUpdatedAt ON tasks(updatedAt DESC)`);
});
}
}
/**

View File

@@ -765,26 +765,59 @@ export function ListView({
[isMobile, onOpenDetail]
);
// Debounce detail fetches so rapid keyboard/mouse navigation through a
// long task list doesn't issue a heavy /tasks/:id request (with log +
// comments) per row. Only the task the user lands on triggers a fetch.
const detailFetchTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const detailFetchTargetRef = useRef<string | null>(null);
useEffect(() => {
return () => {
if (detailFetchTimerRef.current) {
clearTimeout(detailFetchTimerRef.current);
}
};
}, []);
const handleEmbeddedOpenDetail = useCallback((nextTask: Task | TaskDetail) => {
setSelectedTaskId(nextTask.id);
setSelectedTaskSnapshot(nextTask);
if ("prompt" in nextTask) {
detailFetchTargetRef.current = null;
if (detailFetchTimerRef.current) {
clearTimeout(detailFetchTimerRef.current);
detailFetchTimerRef.current = null;
}
return;
}
fetchTaskDetail(nextTask.id, projectId)
.then((detail) => {
setSelectedTaskSnapshot((previous) => {
if (!previous || previous.id !== detail.id) {
return previous;
detailFetchTargetRef.current = nextTask.id;
if (detailFetchTimerRef.current) {
clearTimeout(detailFetchTimerRef.current);
}
detailFetchTimerRef.current = setTimeout(() => {
detailFetchTimerRef.current = null;
const targetId = detailFetchTargetRef.current;
if (targetId !== nextTask.id) {
return;
}
fetchTaskDetail(nextTask.id, projectId)
.then((detail) => {
if (detailFetchTargetRef.current !== detail.id) {
return;
}
return { ...previous, ...detail };
setSelectedTaskSnapshot((previous) => {
if (!previous || previous.id !== detail.id) {
return previous;
}
return { ...previous, ...detail };
});
})
.catch(() => {
// Keep optimistic inline selection when detail fetch fails.
});
})
.catch(() => {
// Keep optimistic inline selection when detail fetch fails.
});
}, 200);
}, [projectId]);
const handleDragStart = useCallback(