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:
@@ -18,23 +18,27 @@ const CACHE_KEY = 'admin:changelog:releases';
|
||||
const CACHE_TTL = 5 * 60; // 5 minutes
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch }) => {
|
||||
// Return cached data synchronously (no streaming needed — already fast).
|
||||
const cached = await cache.get<Release[]>(CACHE_KEY);
|
||||
if (cached) {
|
||||
return { releases: cached };
|
||||
return { releases: cached, error: undefined as string | undefined };
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(GITEA_RELEASES_URL, {
|
||||
headers: { Accept: 'application/json' }
|
||||
});
|
||||
if (!res.ok) {
|
||||
return { releases: [], error: `Gitea API returned ${res.status}` };
|
||||
// Cache miss: stream the external Gitea request so navigation isn't blocked.
|
||||
const releasesPromise = (async () => {
|
||||
try {
|
||||
const res = await fetch(GITEA_RELEASES_URL, {
|
||||
headers: { Accept: 'application/json' }
|
||||
});
|
||||
if (!res.ok) return [] as Release[];
|
||||
const releases: Release[] = await res.json();
|
||||
const filtered = releases.filter((r) => !r.draft);
|
||||
await cache.set(CACHE_KEY, filtered, CACHE_TTL);
|
||||
return filtered;
|
||||
} catch {
|
||||
return [] as Release[];
|
||||
}
|
||||
const releases: Release[] = await res.json();
|
||||
const filtered = releases.filter((r) => !r.draft);
|
||||
await cache.set(CACHE_KEY, filtered, CACHE_TTL);
|
||||
return { releases: filtered };
|
||||
} catch (e) {
|
||||
return { releases: [], error: String(e) };
|
||||
}
|
||||
})();
|
||||
|
||||
return { releases: releasesPromise, error: undefined as string | undefined };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user