perf(workflow): skip unnecessary query subscriptions for non-plugin nodes

Add `enabled` parameter to tool query hooks so non-plugin nodes
(LLM, Code, IfElse, etc.) avoid registering React Query observers.
Extract shared matching functions into plugin-install-check utils to
eliminate duplicate logic between the hook and the checklist.
This commit is contained in:
yyh
2026-01-30 01:46:31 +08:00
parent 5d8ba8f8cc
commit c8a0a2c00d
3 changed files with 97 additions and 87 deletions

View File

@ -31,10 +31,11 @@ export const useInvalidateAllToolProviders = () => {
}
const useAllBuiltInToolsKey = [NAME_SPACE, 'builtIn']
export const useAllBuiltInTools = () => {
export const useAllBuiltInTools = (enabled = true) => {
return useQuery<ToolWithProvider[]>({
queryKey: useAllBuiltInToolsKey,
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/builtin'),
enabled,
})
}
@ -43,10 +44,11 @@ export const useInvalidateAllBuiltInTools = () => {
}
const useAllCustomToolsKey = [NAME_SPACE, 'customTools']
export const useAllCustomTools = () => {
export const useAllCustomTools = (enabled = true) => {
return useQuery<ToolWithProvider[]>({
queryKey: useAllCustomToolsKey,
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/api'),
enabled,
})
}
@ -55,10 +57,11 @@ export const useInvalidateAllCustomTools = () => {
}
const useAllWorkflowToolsKey = [NAME_SPACE, 'workflowTools']
export const useAllWorkflowTools = () => {
export const useAllWorkflowTools = (enabled = true) => {
return useQuery<ToolWithProvider[]>({
queryKey: useAllWorkflowToolsKey,
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/workflow'),
enabled,
})
}
@ -67,10 +70,11 @@ export const useInvalidateAllWorkflowTools = () => {
}
const useAllMCPToolsKey = [NAME_SPACE, 'MCPTools']
export const useAllMCPTools = () => {
export const useAllMCPTools = (enabled = true) => {
return useQuery<ToolWithProvider[]>({
queryKey: useAllMCPToolsKey,
queryFn: () => get<ToolWithProvider[]>('/workspaces/current/tools/mcp'),
enabled,
})
}