Fix duplicated calculation of nodes and dependent nodes are not initialized

This commit is contained in:
YISH
2024-02-28 17:43:36 +08:00
committed by GitHub
parent c4b9de2ddc
commit 8d88608a68
+6 -1
View File
@@ -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<string> = 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]