chore: workflow performance

This commit is contained in:
zxhlyh
2025-10-11 14:02:25 +08:00
parent c90e564d99
commit bf20f3aa8b
2 changed files with 29 additions and 8 deletions

View File

@ -1,16 +1,36 @@
import { useMemo } from 'react'
import { useStore } from 'reactflow' import { useStore } from 'reactflow'
import { useShallow } from 'zustand/react/shallow'
import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils' import { isSystemVar } from '@/app/components/workflow/nodes/_base/components/variable/utils'
import { BlockEnum } from '@/app/components/workflow/types' import { BlockEnum } from '@/app/components/workflow/types'
import type { Node, ValueSelector } from '@/app/components/workflow/types' import type { Node, ValueSelector } from '@/app/components/workflow/types'
export const useFindNode = (valueSelector: ValueSelector = [], nodes: Node[] = []) => { export const useFindNode = (valueSelector: ValueSelector = [], nodes: Node[] = []) => {
const nodeFromOuterNodes = nodes.find(node => node.id === valueSelector[0]) const nodeFromOuterNodes = nodes.find(node => node.id === valueSelector[0])
const node = useStore((s) => { const node = useStore(useShallow((s) => {
const nodes = s.getNodes() if (isSystemVar(valueSelector)) {
if (isSystemVar(valueSelector)) for (const n of s.nodeInternals.values()) {
return nodes.find(node => node.data.type === BlockEnum.Start) if (n?.data?.type === BlockEnum.Start) {
return nodes.find(node => node.id === valueSelector[0]) return {
}) id: n.id,
data: n.data,
}
}
}
}
else {
if (!!valueSelector.length) {
const id = s.nodeInternals.get(valueSelector[0])?.id
const data = s.nodeInternals.get(valueSelector[0])?.data
if (id && data) {
return {
id,
data,
}
}
}
}
}))
return nodeFromOuterNodes || node return useMemo(() => nodeFromOuterNodes || node, [nodeFromOuterNodes, node])
} }

View File

@ -61,6 +61,7 @@ import { CUSTOM_SIMPLE_NODE } from './simple-node/constants'
import CustomDataSourceEmptyNode from './nodes/data-source-empty' import CustomDataSourceEmptyNode from './nodes/data-source-empty'
import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from './nodes/data-source-empty/constants' import { CUSTOM_DATA_SOURCE_EMPTY_NODE } from './nodes/data-source-empty/constants'
import Operator from './operator' import Operator from './operator'
import { useWorkflowSearch } from './hooks/use-workflow-search'
import Control from './operator/control' import Control from './operator/control'
import CustomEdge from './custom-edge' import CustomEdge from './custom-edge'
import CustomConnectionLine from './custom-connection-line' import CustomConnectionLine from './custom-connection-line'
@ -289,7 +290,7 @@ export const Workflow: FC<WorkflowProps> = memo(({
useShortcuts() useShortcuts()
// Initialize workflow node search functionality // Initialize workflow node search functionality
// useWorkflowSearch() useWorkflowSearch()
// Set up scroll to node event listener using the utility function // Set up scroll to node event listener using the utility function
useEffect(() => { useEffect(() => {