perf: defer ai page prefetch
This commit is contained in:
@@ -1091,6 +1091,7 @@ onUnmounted(() => {
|
|||||||
<!-- 侧边栏布局时的设计面板(保持原有行为) -->
|
<!-- 侧边栏布局时的设计面板(保持原有行为) -->
|
||||||
<template v-if="layout === 'sidebar'">
|
<template v-if="layout === 'sidebar'">
|
||||||
<DesignEditorPanel
|
<DesignEditorPanel
|
||||||
|
v-if="showDesignPanel"
|
||||||
:visible="showDesignPanel"
|
:visible="showDesignPanel"
|
||||||
:design="currentDesign as any"
|
:design="currentDesign as any"
|
||||||
@update:visible="showDesignPanel = $event"
|
@update:visible="showDesignPanel = $event"
|
||||||
@@ -1099,6 +1100,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<AppDesignPanel
|
<AppDesignPanel
|
||||||
|
v-if="showAppDesignPanel"
|
||||||
:visible="showAppDesignPanel"
|
:visible="showAppDesignPanel"
|
||||||
:design="currentAppDesign as any"
|
:design="currentAppDesign as any"
|
||||||
@update:visible="showAppDesignPanel = $event"
|
@update:visible="showAppDesignPanel = $event"
|
||||||
@@ -1107,6 +1109,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<AppSettingsPanel
|
<AppSettingsPanel
|
||||||
|
v-if="showAppSettingsPanel"
|
||||||
:visible="showAppSettingsPanel"
|
:visible="showAppSettingsPanel"
|
||||||
:settings="currentAppSettings as any"
|
:settings="currentAppSettings as any"
|
||||||
@update:visible="showAppSettingsPanel = $event"
|
@update:visible="showAppSettingsPanel = $event"
|
||||||
@@ -1115,6 +1118,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DashboardBasicInfoConfirmPanel
|
<DashboardBasicInfoConfirmPanel
|
||||||
|
v-if="showDashboardBasicInfoPanel"
|
||||||
:visible="showDashboardBasicInfoPanel"
|
:visible="showDashboardBasicInfoPanel"
|
||||||
:basic-info="currentDashboardBasicInfo as any"
|
:basic-info="currentDashboardBasicInfo as any"
|
||||||
@update:visible="showDashboardBasicInfoPanel = $event"
|
@update:visible="showDashboardBasicInfoPanel = $event"
|
||||||
@@ -1123,6 +1127,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DashboardDesignConfirmPanel
|
<DashboardDesignConfirmPanel
|
||||||
|
v-if="showDashboardDesignPanel"
|
||||||
:visible="showDashboardDesignPanel"
|
:visible="showDashboardDesignPanel"
|
||||||
:design="currentDashboardDesign as any"
|
:design="currentDashboardDesign as any"
|
||||||
@update:visible="showDashboardDesignPanel = $event"
|
@update:visible="showDashboardDesignPanel = $event"
|
||||||
@@ -1131,6 +1136,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<DashboardPublishConfirmPanel
|
<DashboardPublishConfirmPanel
|
||||||
|
v-if="showDashboardPublishPanel"
|
||||||
:visible="showDashboardPublishPanel"
|
:visible="showDashboardPublishPanel"
|
||||||
:publish-data="currentDashboardPublish as any"
|
:publish-data="currentDashboardPublish as any"
|
||||||
@update:visible="showDashboardPublishPanel = $event"
|
@update:visible="showDashboardPublishPanel = $event"
|
||||||
@@ -1139,6 +1145,7 @@ onUnmounted(() => {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<SystemSummaryConfirmPanel
|
<SystemSummaryConfirmPanel
|
||||||
|
v-if="showSystemSummaryPanel"
|
||||||
:visible="showSystemSummaryPanel"
|
:visible="showSystemSummaryPanel"
|
||||||
:data="currentSystemSummary as any"
|
:data="currentSystemSummary as any"
|
||||||
@update:visible="showSystemSummaryPanel = $event"
|
@update:visible="showSystemSummaryPanel = $event"
|
||||||
|
|||||||
@@ -16,9 +16,11 @@ type NavigatorWithConnection = Navigator & {
|
|||||||
effectiveType?: string;
|
effectiveType?: string;
|
||||||
saveData?: boolean;
|
saveData?: boolean;
|
||||||
};
|
};
|
||||||
|
deviceMemory?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const prefetchedGroups = new Set<string>();
|
const prefetchedGroups = new Set<string>();
|
||||||
|
const scheduledGroups = new Set<string>();
|
||||||
|
|
||||||
type PrefetchTask = {
|
type PrefetchTask = {
|
||||||
key: string;
|
key: string;
|
||||||
@@ -31,39 +33,36 @@ const corePrefetchTasks: PrefetchTask[] = [
|
|||||||
{ key: 'system-role', load: () => import('#/views/_core/role/index.vue') },
|
{ key: 'system-role', load: () => import('#/views/_core/role/index.vue') },
|
||||||
];
|
];
|
||||||
|
|
||||||
const aiInteractivePrefetchTasks: PrefetchTask[] = [
|
const aiPrefetchTasks = {
|
||||||
{
|
agent: {
|
||||||
key: 'agent-chat',
|
|
||||||
load: () => import('#/views/_core/agent-chat/index.vue'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'ai-chat-panel',
|
|
||||||
load: () => import('#/components/ai-chat-panel/AiChatPanel.vue'),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
const aiManagementPrefetchTasks: PrefetchTask[] = [
|
|
||||||
{
|
|
||||||
key: 'ai-agent',
|
key: 'ai-agent',
|
||||||
load: () => import('#/views/ai-platform/agent/index.vue'),
|
load: () => import('#/views/ai-platform/agent/index.vue'),
|
||||||
},
|
},
|
||||||
{
|
agentChat: {
|
||||||
key: 'ai-workflow',
|
key: 'agent-chat',
|
||||||
load: () => import('#/views/ai-platform/workflow/index.vue'),
|
load: () => import('#/views/_core/agent-chat/index.vue'),
|
||||||
},
|
},
|
||||||
{
|
aiChatPanel: {
|
||||||
key: 'ai-model',
|
key: 'ai-chat-panel',
|
||||||
load: () => import('#/views/ai-platform/model/index.vue'),
|
load: () => import('#/components/ai-chat-panel/AiChatPanel.vue'),
|
||||||
},
|
},
|
||||||
{
|
knowledge: {
|
||||||
key: 'ai-knowledge',
|
key: 'ai-knowledge',
|
||||||
load: () => import('#/views/ai-platform/knowledge/index.vue'),
|
load: () => import('#/views/ai-platform/knowledge/index.vue'),
|
||||||
},
|
},
|
||||||
{
|
model: {
|
||||||
|
key: 'ai-model',
|
||||||
|
load: () => import('#/views/ai-platform/model/index.vue'),
|
||||||
|
},
|
||||||
|
workflow: {
|
||||||
|
key: 'ai-workflow',
|
||||||
|
load: () => import('#/views/ai-platform/workflow/index.vue'),
|
||||||
|
},
|
||||||
|
workflowRuns: {
|
||||||
key: 'ai-workflow-runs',
|
key: 'ai-workflow-runs',
|
||||||
load: () => import('#/views/ai-platform/workflow-runs/index.vue'),
|
load: () => import('#/views/ai-platform/workflow-runs/index.vue'),
|
||||||
},
|
},
|
||||||
];
|
} as const;
|
||||||
|
|
||||||
function scheduleIdle(callback: () => void) {
|
function scheduleIdle(callback: () => void) {
|
||||||
const browserWindow = window as WindowWithIdleCallback;
|
const browserWindow = window as WindowWithIdleCallback;
|
||||||
@@ -86,6 +85,11 @@ function canPrefetch() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deviceMemory = (navigator as NavigatorWithConnection).deviceMemory;
|
||||||
|
if (deviceMemory && deviceMemory < 4) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return !/(^|-)2g$/.test(connection?.effectiveType || '');
|
return !/(^|-)2g$/.test(connection?.effectiveType || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,13 +103,18 @@ async function runTasksSequentially(tasks: PrefetchTask[]) {
|
|||||||
}
|
}
|
||||||
prefetchedGroups.add(task.key);
|
prefetchedGroups.add(task.key);
|
||||||
await task.load().catch(() => undefined);
|
await task.load().catch(() => undefined);
|
||||||
|
await new Promise((resolve) => window.setTimeout(resolve, 300));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function delayedPrefetch(tasks: PrefetchTask[], delay: number) {
|
function delayedPrefetch(groupKey: string, tasks: PrefetchTask[], delay: number) {
|
||||||
if (!tasks.length || typeof window === 'undefined') {
|
if (!tasks.length || typeof window === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (scheduledGroups.has(groupKey)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
scheduledGroups.add(groupKey);
|
||||||
|
|
||||||
window.setTimeout(() => {
|
window.setTimeout(() => {
|
||||||
scheduleIdle(() => {
|
scheduleIdle(() => {
|
||||||
@@ -126,29 +135,54 @@ function isAgentChatRoute(path: string) {
|
|||||||
return path.startsWith('/agent-chat/');
|
return path.startsWith('/agent-chat/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAiRoutePrefetchTasks(path: string): PrefetchTask[] {
|
||||||
|
if (path.startsWith('/ai-platform/agent')) {
|
||||||
|
return [aiPrefetchTasks.workflow, aiPrefetchTasks.model];
|
||||||
|
}
|
||||||
|
if (path.startsWith('/ai-platform/workflow-runs')) {
|
||||||
|
return [aiPrefetchTasks.workflow];
|
||||||
|
}
|
||||||
|
if (path.startsWith('/ai-platform/workflow')) {
|
||||||
|
return [aiPrefetchTasks.workflowRuns, aiPrefetchTasks.agent];
|
||||||
|
}
|
||||||
|
if (path.startsWith('/ai-platform/model')) {
|
||||||
|
return [aiPrefetchTasks.agent, aiPrefetchTasks.workflow];
|
||||||
|
}
|
||||||
|
if (path.startsWith('/ai-platform/knowledge')) {
|
||||||
|
return [aiPrefetchTasks.agent];
|
||||||
|
}
|
||||||
|
return [aiPrefetchTasks.agent, aiPrefetchTasks.workflow];
|
||||||
|
}
|
||||||
|
|
||||||
function prefetchAiPlatformPages(currentPath = '') {
|
function prefetchAiPlatformPages(currentPath = '') {
|
||||||
if (typeof window === 'undefined') {
|
if (typeof window === 'undefined') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSystemRoute(currentPath)) {
|
if (isSystemRoute(currentPath)) {
|
||||||
delayedPrefetch(corePrefetchTasks, 6000);
|
delayedPrefetch(`core:${currentPath}`, corePrefetchTasks, 8000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAgentChatRoute(currentPath)) {
|
if (isAgentChatRoute(currentPath)) {
|
||||||
delayedPrefetch(aiInteractivePrefetchTasks, 1500);
|
delayedPrefetch(
|
||||||
|
`agent-chat:${currentPath}`,
|
||||||
|
[aiPrefetchTasks.agentChat, aiPrefetchTasks.aiChatPanel],
|
||||||
|
6000,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAiPlatformRoute(currentPath)) {
|
if (isAiPlatformRoute(currentPath)) {
|
||||||
delayedPrefetch(aiManagementPrefetchTasks, 2000);
|
delayedPrefetch(
|
||||||
delayedPrefetch(aiInteractivePrefetchTasks, 4500);
|
`ai:${currentPath}`,
|
||||||
|
getAiRoutePrefetchTasks(currentPath),
|
||||||
|
6000,
|
||||||
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delayedPrefetch(corePrefetchTasks, 7000);
|
delayedPrefetch('core:home', corePrefetchTasks, 10_000);
|
||||||
delayedPrefetch(aiInteractivePrefetchTasks, 12_000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export { prefetchAiPlatformPages };
|
export { prefetchAiPlatformPages };
|
||||||
|
|||||||
Reference in New Issue
Block a user