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 = [
|
||||
|
||||
Reference in New Issue
Block a user