diff --git a/packages/system/src/utils/graph.ts b/packages/system/src/utils/graph.ts index dca0dacc..e72642be 100644 --- a/packages/system/src/utils/graph.ts +++ b/packages/system/src/utils/graph.ts @@ -43,8 +43,14 @@ export const getOutgoersBase = e.source === node.id).map((e) => e.target); - return nodes.filter((n) => outgoerIds.includes(n.id)); + const outgoerIds = new Set(); + edges.forEach((edge) => { + if (edge.source === node.id) { + outgoerIds.add(edge.target); + } + }); + + return nodes.filter((n) => outgoerIds.has(n.id)); }; export const getIncomersBase = ( @@ -55,9 +61,14 @@ export const getIncomersBase = { + if (edge.target === node.id) { + incomersIds.add(edge.source); + } + }); - const incomersIds = edges.filter((e) => e.target === node.id).map((e) => e.source); - return nodes.filter((n) => incomersIds.includes(n.id)); + return nodes.filter((n) => incomersIds.has(n.id)); }; export const getNodePositionWithOrigin = (