mirror of
https://github.com/langgenius/dify.git
synced 2026-10-30 18:34:29 +08:00
fix: workflow online users polling for large app lists (#35786)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
@@ -187,15 +187,16 @@ const List: FC<Props> = ({
|
||||
}, [isCreatedByMe, setQuery])
|
||||
|
||||
const pages = useMemo(() => data?.pages ?? [], [data?.pages])
|
||||
const appIds = useMemo(() => {
|
||||
const ids = new Set<string>()
|
||||
pages.forEach((page) => {
|
||||
page.data?.forEach((app) => {
|
||||
if (app.id)
|
||||
ids.add(app.id)
|
||||
|
||||
const workflowOnlineUserAppIds = useMemo(() => {
|
||||
const appIds = new Set<string>()
|
||||
pages.forEach(({ data: apps }) => {
|
||||
apps.forEach((app) => {
|
||||
if (app.mode === AppModeEnum.WORKFLOW || app.mode === AppModeEnum.ADVANCED_CHAT)
|
||||
appIds.add(app.id)
|
||||
})
|
||||
})
|
||||
return Array.from(ids)
|
||||
return Array.from(appIds)
|
||||
}, [pages])
|
||||
|
||||
const refreshWorkflowOnlineUsers = useCallback(async () => {
|
||||
@@ -204,19 +205,19 @@ const List: FC<Props> = ({
|
||||
return
|
||||
}
|
||||
|
||||
if (!appIds.length) {
|
||||
if (!workflowOnlineUserAppIds.length) {
|
||||
setWorkflowOnlineUsersMap({})
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const onlineUsersMap = await fetchWorkflowOnlineUsers({ appIds })
|
||||
const onlineUsersMap = await fetchWorkflowOnlineUsers({ appIds: workflowOnlineUserAppIds })
|
||||
setWorkflowOnlineUsersMap(onlineUsersMap)
|
||||
}
|
||||
catch {
|
||||
setWorkflowOnlineUsersMap({})
|
||||
}
|
||||
}, [appIds, systemFeatures.enable_collaboration_mode])
|
||||
}, [systemFeatures.enable_collaboration_mode, workflowOnlineUserAppIds])
|
||||
|
||||
useEffect(() => {
|
||||
void refreshWorkflowOnlineUsers()
|
||||
|
||||
@@ -17,11 +17,11 @@ export const appDeleteContract = base
|
||||
export const workflowOnlineUsersContract = base
|
||||
.route({
|
||||
path: '/apps/workflows/online-users',
|
||||
method: 'GET',
|
||||
method: 'POST',
|
||||
})
|
||||
.input(type<{
|
||||
query: {
|
||||
app_ids: string
|
||||
body: {
|
||||
app_ids: string[]
|
||||
}
|
||||
}>())
|
||||
.output(type<WorkflowOnlineUsersResponse>())
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ export const fetchWorkflowOnlineUsers = async ({ appIds }: { appIds: string[] })
|
||||
return {}
|
||||
|
||||
const response = await consoleClient.apps.workflowOnlineUsers({
|
||||
query: { app_ids: appIds.join(',') },
|
||||
body: { app_ids: appIds },
|
||||
})
|
||||
|
||||
if (!response?.data)
|
||||
|
||||
Reference in New Issue
Block a user