From 8d88608a6857bbce5f100f0157e02dad683fbc5e Mon Sep 17 00:00:00 2001 From: YISH Date: Wed, 28 Feb 2024 17:43:36 +0800 Subject: [PATCH 1/4] Fix duplicated calculation of nodes and dependent nodes are not initialized --- packages/server/src/utils/index.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 8092fbd8..afd8e403 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -298,7 +298,9 @@ export const buildFlow = async ( nodeQueue.push({ nodeId: startingNodeIds[i], depth: 0 }) exploredNode[startingNodeIds[i]] = { remainingLoop: maxLoop, lastSeenDepth: 0 } } - + + const initializedNode: Set = new Set() + const nonDirectedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph while (nodeQueue.length) { const { nodeId, depth } = nodeQueue.shift() as INodeQueue @@ -384,6 +386,7 @@ export const buildFlow = async ( flowNodes[nodeIndex].data.instance = outputResult logger.debug(`[server]: Finished initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`) + initializedNode.add(reactFlowNode.data.id) } } catch (e: any) { logger.error(e) @@ -406,6 +409,8 @@ export const buildFlow = async ( for (let i = 0; i < neighbourNodeIds.length; i += 1) { const neighNodeId = neighbourNodeIds[i] if (ignoreNodeIds.includes(neighNodeId)) continue + if (initializedNode.has(neighNodeId)) continue + if (nonDirectedGraph[neighNodeId].some((dependId) => !initializedNode.has(dependId))) continue // If nodeId has been seen, cycle detected if (Object.prototype.hasOwnProperty.call(exploredNode, neighNodeId)) { const { remainingLoop, lastSeenDepth } = exploredNode[neighNodeId] From ceebd3e11ae4279ee1c64dedc24a0a89d7ff978b Mon Sep 17 00:00:00 2001 From: YISH Date: Wed, 28 Feb 2024 18:19:56 +0800 Subject: [PATCH 2/4] Update index.ts --- packages/server/src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index afd8e403..1af3ef3f 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -298,7 +298,7 @@ export const buildFlow = async ( nodeQueue.push({ nodeId: startingNodeIds[i], depth: 0 }) exploredNode[startingNodeIds[i]] = { remainingLoop: maxLoop, lastSeenDepth: 0 } } - + const initializedNode: Set = new Set() const nonDirectedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph while (nodeQueue.length) { From 0b6e576fa057248855a071e1f8a1591edef3acd4 Mon Sep 17 00:00:00 2001 From: YISH Date: Wed, 28 Feb 2024 21:30:35 +0800 Subject: [PATCH 3/4] Update index.ts --- packages/server/src/utils/index.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index 1af3ef3f..c96139d7 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -299,7 +299,7 @@ export const buildFlow = async ( exploredNode[startingNodeIds[i]] = { remainingLoop: maxLoop, lastSeenDepth: 0 } } - const initializedNode: Set = new Set() + const initializedNodes: Set = new Set() const nonDirectedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph while (nodeQueue.length) { const { nodeId, depth } = nodeQueue.shift() as INodeQueue @@ -386,7 +386,7 @@ export const buildFlow = async ( flowNodes[nodeIndex].data.instance = outputResult logger.debug(`[server]: Finished initializing ${reactFlowNode.data.label} (${reactFlowNode.data.id})`) - initializedNode.add(reactFlowNode.data.id) + initializedNodes.add(reactFlowNode.data.id) } } catch (e: any) { logger.error(e) @@ -409,8 +409,8 @@ export const buildFlow = async ( for (let i = 0; i < neighbourNodeIds.length; i += 1) { const neighNodeId = neighbourNodeIds[i] if (ignoreNodeIds.includes(neighNodeId)) continue - if (initializedNode.has(neighNodeId)) continue - if (nonDirectedGraph[neighNodeId].some((dependId) => !initializedNode.has(dependId))) continue + if (initializedNodes.has(neighNodeId)) continue + if (nonDirectedGraph[neighNodeId].some((dependId) => !initializedNodes.has(dependId))) continue // If nodeId has been seen, cycle detected if (Object.prototype.hasOwnProperty.call(exploredNode, neighNodeId)) { const { remainingLoop, lastSeenDepth } = exploredNode[neighNodeId] From b62510443392398e7f31ddee28a1e0c8a1edf74b Mon Sep 17 00:00:00 2001 From: YISH Date: Mon, 11 Mar 2024 20:00:43 +0800 Subject: [PATCH 4/4] Update index.ts --- packages/server/src/utils/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/server/src/utils/index.ts b/packages/server/src/utils/index.ts index c96139d7..656e11a3 100644 --- a/packages/server/src/utils/index.ts +++ b/packages/server/src/utils/index.ts @@ -300,7 +300,7 @@ export const buildFlow = async ( } const initializedNodes: Set = new Set() - const nonDirectedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph + const reversedGraph = constructGraphs(reactFlowNodes, reactFlowEdges, { isReversed: true }).graph while (nodeQueue.length) { const { nodeId, depth } = nodeQueue.shift() as INodeQueue @@ -410,7 +410,7 @@ export const buildFlow = async ( const neighNodeId = neighbourNodeIds[i] if (ignoreNodeIds.includes(neighNodeId)) continue if (initializedNodes.has(neighNodeId)) continue - if (nonDirectedGraph[neighNodeId].some((dependId) => !initializedNodes.has(dependId))) continue + if (reversedGraph[neighNodeId].some((dependId) => !initializedNodes.has(dependId))) continue // If nodeId has been seen, cycle detected if (Object.prototype.hasOwnProperty.call(exploredNode, neighNodeId)) { const { remainingLoop, lastSeenDepth } = exploredNode[neighNodeId]