卡顿问题

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 recursiveFindParentNode = (
nodeList: SimpleFlowNode[],
findNode: SimpleFlowNode,
nodeType: number
nodeList: SimpleFlowNode[],
findNode: SimpleFlowNode,
nodeType: number
) => {
if (!findNode) return
//
const cacheKey = `${findNode.id}-${nodeType}`
if (nodeCache.has(cacheKey)) {
const cachedNodes = nodeCache.get(cacheKey)
nodeList.push(...cachedNodes!)
return
}
const foundNodes: SimpleFlowNode[] = []
//
if (findNode.type === nodeType) {
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)
// Create a Set to track visited nodes and prevent cycles
const visitedNodes = new Set<string>()
const findNodesRecursive = (node: SimpleFlowNode) => {
if (!node || visitedNodes.has(node.id)) return
visitedNodes.add(node.id)
// Check current node
if (node.type === nodeType) {
if (!nodeList.some(n => n.id === node.id)) {
nodeList.push(node)
}
})
}
// 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)
}
})
}
}
//
nodeCache.set(cacheKey, foundNodes)
nodeList.push(...foundNodes)
// Start recursive search
findNodesRecursive(findNode)
//
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
// Continue search in parent node
if (props.parentNode) {
emits('find:recursiveFindParentNode', nodeList, props.parentNode, nodeType)
}
}
</script>
<style lang="scss" scoped></style>