Keep the proxy app fast with many flows

The app held every flow in memory and redid all of its work for each new
one: the sidebar mounted every domain and path node (its tree scrolled
inside a container that never bounded it), every tree row looked up its
atoms by scanning every atom the family had made, and the layout, detail
pane and list rows re-rendered per flow. At 3,000 flows each new one cost
about 90 ms of main thread, more than the traffic left time for.

The app now holds a window of the newest 2,000 flows, applies new ones in
batches, and loads older ones in pages from the database on scrolling to
the top, through a new list_flows RPC that pages in SQL. The database
keeps every flow.

Also adds clear_flows: an RPC, POST /flows/clear on the control API, and
a Clear button in the header that Cmd+K opens, confirming first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Gregory SchierandClaude Opus 5.5 authored and Stetta task tk_mvsazf4rsaotrdpf committed 2026-10-28 09:52:00 -07:00
1 parent 4abc882e13
commit 1a994f7532
19 files changed
+855 -216

No files matched your search

+34 -16
View File
@@ -2,16 +2,33 @@ import { atom } from "jotai";
import { atomFamily } from "jotai-family";
import { selectAtom } from "jotai/utils";
/**
* An atom family for object params, looked up by a string key. `atomFamily` with a comparator
* scans every atom it has made on each lookup, which every rendered row does several times a
* render, so a large tree slowed down in proportion to the rows it had ever shown.
*/
function keyedFamily<P, A>(key: (param: P) => string, create: (param: P) => A): (param: P) => A {
const atoms = new Map<string, A>();
return (param) => {
const k = key(param);
let a = atoms.get(k);
if (a === undefined) {
a = create(param);
atoms.set(k, a);
}
return a;
};
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
export const selectedIdsFamily = atomFamily((_treeId: string) => {
return atom<string[]>([]);
});
export const isSelectedFamily = atomFamily(
({ treeId, itemId }: { treeId: string; itemId: string }) => {
return selectAtom(selectedIdsFamily(treeId), (ids) => ids.includes(itemId), Object.is);
},
(a, b) => a.treeId === b.treeId && a.itemId === b.itemId,
export const isSelectedFamily = keyedFamily(
({ treeId, itemId }: { treeId: string; itemId: string }) => `${treeId}\0${itemId}`,
({ treeId, itemId }) =>
selectAtom(selectedIdsFamily(treeId), (ids) => ids.includes(itemId), Object.is),
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -19,10 +36,9 @@ export const focusIdsFamily = atomFamily((_treeId: string) => {
return atom<{ lastId: string | null; anchorId: string | null }>({ lastId: null, anchorId: null });
});
export const isLastFocusedFamily = atomFamily(
({ treeId, itemId }: { treeId: string; itemId: string }) =>
selectAtom(focusIdsFamily(treeId), (v) => v.lastId === itemId, Object.is),
(a, b) => a.treeId === b.treeId && a.itemId === b.itemId,
export const isLastFocusedFamily = keyedFamily(
({ treeId, itemId }: { treeId: string; itemId: string }) => `${treeId}\0${itemId}`,
({ treeId, itemId }) => selectAtom(focusIdsFamily(treeId), (v) => v.lastId === itemId, Object.is),
);
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -45,26 +61,28 @@ export const hoveredParentFamily = atomFamily((_treeId: string) => {
});
});
export const isParentHoveredFamily = atomFamily(
export const isParentHoveredFamily = keyedFamily(
({ treeId, parentId }: { treeId: string; parentId: string | null }) =>
`${treeId}\0${parentId ?? ""}`,
({ treeId, parentId }) =>
selectAtom(hoveredParentFamily(treeId), (v) => v.parentId === parentId, Object.is),
(a, b) => a.treeId === b.treeId && a.parentId === b.parentId,
);
export const isAncestorHoveredFamily = atomFamily(
export const isAncestorHoveredFamily = keyedFamily(
({ treeId, ancestorIds }: { treeId: string; ancestorIds: string[] }) =>
`${treeId}\0${ancestorIds.join(",")}`,
({ treeId, ancestorIds }) =>
selectAtom(
hoveredParentFamily(treeId),
(v) => v.parentId && ancestorIds.includes(v.parentId),
Object.is,
),
(a, b) => a.treeId === b.treeId && a.ancestorIds.join(",") === b.ancestorIds.join(","),
);
export const isIndexHoveredFamily = atomFamily(
({ treeId, index }: { treeId: string; index: number }) =>
export const isIndexHoveredFamily = keyedFamily(
({ treeId, index }: { treeId: string; index: number }) => `${treeId}\0${index}`,
({ treeId, index }) =>
selectAtom(hoveredParentFamily(treeId), (v) => v.index === index, Object.is),
(a, b) => a.treeId === b.treeId && a.index === b.index,
);
export const hoveredParentDepthFamily = atomFamily((treeId: string) =>