mirror of
https://github.com/langgenius/dify.git
synced 2026-05-05 01:48:04 +08:00
chore: workflow performance
This commit is contained in:
@ -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])
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user