perf: stream slow load functions in admin pages to unblock navigation
- image-gen, text-gen: books list streamed (listBooks is expensive on cold cache) - ai-jobs: jobs list streamed; add 30s cache to listAIJobs (was uncached listAll) - changelog: Gitea releases streamed on cold cache; cached path stays synchronous - admin/+layout.svelte: remove duplicate audio/translation/image-gen nav links
This commit is contained in:
@@ -17,21 +17,23 @@ export interface TextModelInfo {
|
||||
}
|
||||
|
||||
export const load: PageServerLoad = async () => {
|
||||
// Parent layout already guards admin role.
|
||||
const [models, booksResult] = await Promise.allSettled([
|
||||
listTextModels<TextModelInfo>(),
|
||||
listBooks()
|
||||
]);
|
||||
// Await models immediately — in-memory list, no I/O, returns instantly.
|
||||
// Books are streamed so the page renders at once and the selector
|
||||
// populates a moment later without blocking navigation.
|
||||
const modelsResult = await listTextModels<TextModelInfo>().catch((e) => {
|
||||
log.warn('admin/text-gen', 'failed to load models', { err: String(e) });
|
||||
return [] as TextModelInfo[];
|
||||
});
|
||||
|
||||
if (models.status === 'rejected') {
|
||||
log.warn('admin/text-gen', 'failed to load models', { err: String(models.reason) });
|
||||
}
|
||||
const booksPromise = listBooks()
|
||||
.then((all) =>
|
||||
all.map((b) => ({ slug: b.slug, title: b.title })) as BookSummary[]
|
||||
)
|
||||
.catch(() => [] as BookSummary[]);
|
||||
|
||||
return {
|
||||
models: models.status === 'fulfilled' ? models.value : ([] as TextModelInfo[]),
|
||||
books: (booksResult.status === 'fulfilled' ? booksResult.value : []).map((b) => ({
|
||||
slug: b.slug,
|
||||
title: b.title
|
||||
})) as BookSummary[]
|
||||
models: modelsResult,
|
||||
// Streamed — SvelteKit resolves this after the initial HTML is sent.
|
||||
books: booksPromise
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user