fix: warm admin pages earlier
This commit is contained in:
@@ -93,38 +93,35 @@ function withAdminRuntimePages(pageMap: ComponentRecordType) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const PREFETCH_LIGHT_PAGE_KEYS = [
|
const PREFETCH_LIGHT_PAGE_KEYS = [
|
||||||
'../views/_core/menu/index.vue',
|
|
||||||
'../views/_core/permission/index.vue',
|
|
||||||
'../views/_core/role/index.vue',
|
|
||||||
'../views/_core/user/index.vue',
|
'../views/_core/user/index.vue',
|
||||||
|
'../views/_core/menu/index.vue',
|
||||||
|
'../views/_core/role/index.vue',
|
||||||
|
'../views/_core/permission/index.vue',
|
||||||
];
|
];
|
||||||
|
|
||||||
let lightPagesPrefetched = false;
|
let lightPagesPrefetched = false;
|
||||||
|
|
||||||
function scheduleIdleTask(callback: () => void) {
|
function scheduleLightPrefetch(callback: () => void, delay: number) {
|
||||||
if (typeof window === 'undefined') return;
|
if (typeof window === 'undefined') return;
|
||||||
const requestIdle = (window as any).requestIdleCallback;
|
window.setTimeout(callback, delay);
|
||||||
if (typeof requestIdle === 'function') {
|
|
||||||
requestIdle(callback, { timeout: 8000 });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
window.setTimeout(callback, 8000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function prefetchLightPages(pageMap: ComponentRecordType) {
|
function prefetchLightPages(pageMap: ComponentRecordType) {
|
||||||
if (lightPagesPrefetched) return;
|
if (lightPagesPrefetched) return;
|
||||||
lightPagesPrefetched = true;
|
lightPagesPrefetched = true;
|
||||||
window.setTimeout(() => {
|
|
||||||
scheduleIdleTask(() => {
|
scheduleLightPrefetch(() => {
|
||||||
void ensureAdminRuntime().catch(() => undefined);
|
void ensureAdminRuntime().catch(() => undefined);
|
||||||
for (const key of PREFETCH_LIGHT_PAGE_KEYS) {
|
}, 250);
|
||||||
const loader = pageMap[key];
|
|
||||||
if (typeof loader === 'function') {
|
for (const [index, key] of PREFETCH_LIGHT_PAGE_KEYS.entries()) {
|
||||||
void loader().catch(() => undefined);
|
scheduleLightPrefetch(() => {
|
||||||
}
|
const loader = pageMap[key];
|
||||||
|
if (typeof loader === 'function') {
|
||||||
|
void loader().catch(() => undefined);
|
||||||
}
|
}
|
||||||
});
|
}, 450 + index * 160);
|
||||||
}, 3_000);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LIGHT_AI_PLATFORM_MENU_ROUTES = [
|
const LIGHT_AI_PLATFORM_MENU_ROUTES = [
|
||||||
|
|||||||
@@ -25,21 +25,17 @@ function filterLightTabHistory<T extends { tabs?: unknown[] }>(history: T) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function isMainHomeRoute(path: string) {
|
let adminRuntimeWarmupScheduled = false;
|
||||||
return /\/page-render\/main_home$/.test(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
function warmAdminRuntimeAfterPaint() {
|
function warmAdminRuntimeAfterPaint() {
|
||||||
|
if (adminRuntimeWarmupScheduled) return;
|
||||||
|
adminRuntimeWarmupScheduled = true;
|
||||||
|
|
||||||
const run = () => {
|
const run = () => {
|
||||||
void ensureAdminRuntime();
|
void ensureAdminRuntime().catch(() => undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
if ('requestIdleCallback' in window) {
|
window.setTimeout(run, 350);
|
||||||
window.requestIdleCallback(run, { timeout: 2000 });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
window.setTimeout(run, 800);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,10 +127,8 @@ function setupCommonGuard(router: Router) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (useAccessStore().accessToken) {
|
if (useAccessStore().accessToken) {
|
||||||
|
warmAdminRuntimeAfterPaint();
|
||||||
prefetchAiPlatformPages(to.path);
|
prefetchAiPlatformPages(to.path);
|
||||||
if (isMainHomeRoute(to.path)) {
|
|
||||||
warmAdminRuntimeAfterPaint();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,11 +68,11 @@ function scheduleIdle(callback: () => void) {
|
|||||||
const browserWindow = window as WindowWithIdleCallback;
|
const browserWindow = window as WindowWithIdleCallback;
|
||||||
|
|
||||||
if (browserWindow.requestIdleCallback) {
|
if (browserWindow.requestIdleCallback) {
|
||||||
browserWindow.requestIdleCallback(callback, { timeout: 8000 });
|
browserWindow.requestIdleCallback(callback, { timeout: 2000 });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.setTimeout(callback, 8000);
|
window.setTimeout(callback, 1200);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canPrefetch() {
|
function canPrefetch() {
|
||||||
@@ -160,7 +160,7 @@ function prefetchAiPlatformPages(currentPath = '') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isSystemRoute(currentPath)) {
|
if (isSystemRoute(currentPath)) {
|
||||||
delayedPrefetch(`core:${currentPath}`, corePrefetchTasks, 18_000);
|
delayedPrefetch(`core:${currentPath}`, corePrefetchTasks, 4_000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,7 @@ function prefetchAiPlatformPages(currentPath = '') {
|
|||||||
delayedPrefetch(
|
delayedPrefetch(
|
||||||
`agent-chat:${currentPath}`,
|
`agent-chat:${currentPath}`,
|
||||||
[aiPrefetchTasks.agentChat, aiPrefetchTasks.aiChatPanel],
|
[aiPrefetchTasks.agentChat, aiPrefetchTasks.aiChatPanel],
|
||||||
14_000,
|
3_000,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -177,12 +177,21 @@ function prefetchAiPlatformPages(currentPath = '') {
|
|||||||
delayedPrefetch(
|
delayedPrefetch(
|
||||||
`ai:${currentPath}`,
|
`ai:${currentPath}`,
|
||||||
getAiRoutePrefetchTasks(currentPath),
|
getAiRoutePrefetchTasks(currentPath),
|
||||||
14_000,
|
3_000,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
delayedPrefetch('core:home', corePrefetchTasks, 22_000);
|
delayedPrefetch('core:home', corePrefetchTasks, 4_500);
|
||||||
|
delayedPrefetch(
|
||||||
|
'ai:home',
|
||||||
|
[
|
||||||
|
aiPrefetchTasks.agentChat,
|
||||||
|
aiPrefetchTasks.model,
|
||||||
|
aiPrefetchTasks.workflowRuns,
|
||||||
|
],
|
||||||
|
7_000,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { prefetchAiPlatformPages };
|
export { prefetchAiPlatformPages };
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import type { WorkflowRunListItem } from '#/api/ai-platform/ai-platform';
|
import type { WorkflowRunListItem } from '#/api/ai-platform/ai-platform';
|
||||||
|
|
||||||
import { ref } from 'vue';
|
import { defineAsyncComponent, ref } from 'vue';
|
||||||
|
|
||||||
import { Page } from '@vben/common-ui';
|
import { Page } from '@vben/common-ui';
|
||||||
import { Eye } from '@vben/icons';
|
import { Eye } from '@vben/icons';
|
||||||
@@ -23,10 +23,13 @@ import {
|
|||||||
useSearchFormSchema,
|
useSearchFormSchema,
|
||||||
useZqTableColumns,
|
useZqTableColumns,
|
||||||
} from './data';
|
} from './data';
|
||||||
import DetailDialog from './modules/detail-dialog.vue';
|
|
||||||
|
|
||||||
defineOptions({ name: 'WorkflowRunHistory' });
|
defineOptions({ name: 'WorkflowRunHistory' });
|
||||||
|
|
||||||
|
const DetailDialog = defineAsyncComponent(
|
||||||
|
() => import('./modules/detail-dialog.vue'),
|
||||||
|
);
|
||||||
|
|
||||||
const appContextStore = useAppContextStore();
|
const appContextStore = useAppContextStore();
|
||||||
const detailRef = ref<InstanceType<typeof DetailDialog>>();
|
const detailRef = ref<InstanceType<typeof DetailDialog>>();
|
||||||
const triggerOptions = getTriggerOptions();
|
const triggerOptions = getTriggerOptions();
|
||||||
|
|||||||
Reference in New Issue
Block a user