卡顿问题

pull/710/head
Lemon 2025-02-25 18:55:59 +08:00
parent 9b04918118
commit 5e3d89e279
1 changed files with 37 additions and 38 deletions

View File

@ -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>