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