fix: update refresh logic for plugin list to avoid redundant request and fix model provider list update issue in settings (#14152)

This commit is contained in:
Wu Tianwei 2025-02-24 10:49:43 +08:00 committed by GitHub
parent 2ace9ae4e4
commit 3942e45cab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 10 deletions

View File

@ -23,17 +23,15 @@ const useRefreshPluginList = () => {
// installed list // installed list
invalidateInstalledPluginList() invalidateInstalledPluginList()
if (!manifest) return
// tool page, tool select // tool page, tool select
if (PluginType.tool.includes(manifest.category) || refreshAllType) { if ((manifest && PluginType.tool.includes(manifest.category)) || refreshAllType) {
invalidateAllToolProviders() invalidateAllToolProviders()
invalidateAllBuiltInTools() invalidateAllBuiltInTools()
// TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins // TODO: update suggested tools. It's a function in hook useMarketplacePlugins,handleUpdatePlugins
} }
// model select // model select
if (PluginType.model.includes(manifest.category) || refreshAllType) { if ((manifest && PluginType.model.includes(manifest.category)) || refreshAllType) {
refreshModelProviders() refreshModelProviders()
refetchLLMModelList() refetchLLMModelList()
refetchEmbeddingModelList() refetchEmbeddingModelList()
@ -41,7 +39,7 @@ const useRefreshPluginList = () => {
} }
// agent select // agent select
if (PluginType.agent.includes(manifest.category) || refreshAllType) if ((manifest && PluginType.agent.includes(manifest.category)) || refreshAllType)
invalidateStrategyProviders() invalidateStrategyProviders()
}, },
} }

View File

@ -1,4 +1,4 @@
import { useCallback } from 'react' import { useCallback, useEffect } from 'react'
import type { import type {
ModelProvider, ModelProvider,
} from '@/app/components/header/account-setting/model-provider-page/declarations' } from '@/app/components/header/account-setting/model-provider-page/declarations'
@ -39,6 +39,7 @@ import { useInvalidateAllBuiltInTools } from './use-tools'
import usePermission from '@/app/components/plugins/plugin-page/use-permission' import usePermission from '@/app/components/plugins/plugin-page/use-permission'
import { uninstallPlugin } from '@/service/plugins' import { uninstallPlugin } from '@/service/plugins'
import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list' import useRefreshPluginList from '@/app/components/plugins/install-plugin/hooks/use-refresh-plugin-list'
import { cloneDeep } from 'lodash-es'
const NAME_SPACE = 'plugins' const NAME_SPACE = 'plugins'
@ -383,6 +384,7 @@ export const usePluginTaskList = (category?: PluginType) => {
const { const {
data, data,
isFetched, isFetched,
isRefetching,
refetch, refetch,
...rest ...rest
} = useQuery({ } = useQuery({
@ -392,16 +394,24 @@ export const usePluginTaskList = (category?: PluginType) => {
refetchInterval: (lastQuery) => { refetchInterval: (lastQuery) => {
const lastData = lastQuery.state.data const lastData = lastQuery.state.data
const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed) const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed)
return taskDone ? false : 5000
},
})
useEffect(() => {
// After first fetch, refresh plugin list each time all tasks are done
if (!isRefetching) {
const lastData = cloneDeep(data)
const taskDone = lastData?.tasks.every(task => task.status === TaskStatus.success || task.status === TaskStatus.failed)
const taskAllFailed = lastData?.tasks.every(task => task.status === TaskStatus.failed) const taskAllFailed = lastData?.tasks.every(task => task.status === TaskStatus.failed)
if (taskDone) { if (taskDone) {
if (lastData?.tasks.length && !taskAllFailed) if (lastData?.tasks.length && !taskAllFailed)
refreshPluginList(category ? { category } as any : undefined, !category) refreshPluginList(category ? { category } as any : undefined, !category)
return false
} }
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isRefetching])
return 5000
},
})
const handleRefetch = useCallback(() => { const handleRefetch = useCallback(() => {
refetch() refetch()
}, [refetch]) }, [refetch])