卡顿问题
parent
9b04918118
commit
5e3d89e279
|
|
@ -144,50 +144,49 @@ const findFromParentNode = (nodeList: SimpleFlowNode[], nodeType: number) => {
|
||||||
const nodeCache = new Map<string, SimpleFlowNode[]>()
|
const nodeCache = new Map<string, SimpleFlowNode[]>()
|
||||||
|
|
||||||
const recursiveFindParentNode = (
|
const recursiveFindParentNode = (
|
||||||
nodeList: SimpleFlowNode[],
|
nodeList: SimpleFlowNode[],
|
||||||
findNode: SimpleFlowNode,
|
findNode: SimpleFlowNode,
|
||||||
nodeType: number
|
nodeType: number
|
||||||
) => {
|
) => {
|
||||||
if (!findNode) return
|
if (!findNode) return
|
||||||
|
|
||||||
// 检查缓存
|
// Create a Set to track visited nodes and prevent cycles
|
||||||
const cacheKey = `${findNode.id}-${nodeType}`
|
const visitedNodes = new Set<string>()
|
||||||
if (nodeCache.has(cacheKey)) {
|
|
||||||
const cachedNodes = nodeCache.get(cacheKey)
|
const findNodesRecursive = (node: SimpleFlowNode) => {
|
||||||
nodeList.push(...cachedNodes!)
|
if (!node || visitedNodes.has(node.id)) return
|
||||||
return
|
|
||||||
}
|
visitedNodes.add(node.id)
|
||||||
|
|
||||||
const foundNodes: SimpleFlowNode[] = []
|
// Check current node
|
||||||
|
if (node.type === nodeType) {
|
||||||
// 检查当前节点
|
if (!nodeList.some(n => n.id === node.id)) {
|
||||||
if (findNode.type === nodeType) {
|
nodeList.push(node)
|
||||||
foundNodes.push(findNode)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查子节点
|
|
||||||
if (findNode.childNode) {
|
|
||||||
if (findNode.childNode.type === nodeType) {
|
|
||||||
foundNodes.push(findNode.childNode)
|
|
||||||
}
|
|
||||||
recursiveFindParentNode(foundNodes, findNode.childNode, nodeType)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查条件分支节点
|
|
||||||
if (findNode.type === NodeType.CONDITION_BRANCH_NODE && findNode.conditionNodes) {
|
|
||||||
findNode.conditionNodes.forEach(conditionNode => {
|
|
||||||
if (conditionNode.childNode) {
|
|
||||||
recursiveFindParentNode(foundNodes, conditionNode.childNode, nodeType)
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
|
// Check child node
|
||||||
|
if (node.childNode) {
|
||||||
|
findNodesRecursive(node.childNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check condition nodes if present
|
||||||
|
if (node.type === NodeType.CONDITION_BRANCH_NODE && node.conditionNodes) {
|
||||||
|
node.conditionNodes.forEach(conditionNode => {
|
||||||
|
if (conditionNode.childNode) {
|
||||||
|
findNodesRecursive(conditionNode.childNode)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 存入缓存
|
// Start recursive search
|
||||||
nodeCache.set(cacheKey, foundNodes)
|
findNodesRecursive(findNode)
|
||||||
nodeList.push(...foundNodes)
|
|
||||||
|
|
||||||
// 继续向上递归查找
|
// Continue search in parent node
|
||||||
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
|
if (props.parentNode) {
|
||||||
|
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped></style>
|
<style lang="scss" scoped></style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue