perf: reuse locals.session from hook instead of re-awaiting locals.auth()

hooks.server.ts already awaits auth() once and stores the result on
locals.session. In-scope loaders (recipe list + filter views, rosary,
prayers, calendar — already done — and fitness stats) were awaiting
locals.auth() a second time per request.

Switched to the existing `locals.session ?? await locals.auth()` pattern
so the hook's result is reused. Also pulls session out of Promise.all
legs since it's now synchronous when the hook ran.

Scope: loaders only — actions, /admin, /edit, /add intentionally skipped.
This commit is contained in:
2026-04-23 15:06:05 +02:00
parent dfeeeb5fdf
commit 800a544190
14 changed files with 28 additions and 35 deletions
+4 -4
View File
@@ -8,7 +8,7 @@ import type { Session } from '@auth/sveltekit';
type BriefRecipeWithFavorite = BriefRecipeType & { isFavorite: boolean };
export async function getUserFavorites(fetch: typeof globalThis.fetch, locals: App.Locals, recipeLang = 'rezepte'): Promise<string[]> {
const session = await locals.auth();
const session = locals.session ?? await locals.auth();
if (!session?.user?.nickname) {
return [];
@@ -47,10 +47,10 @@ export async function loadRecipesWithFavorites(
recipeLoader: () => Promise<BriefRecipeType[]>,
recipeLang = 'rezepte'
): Promise<{ recipes: BriefRecipeWithFavorite[], session: Session | null }> {
const [recipes, userFavorites, session] = await Promise.all([
const session = locals.session ?? await locals.auth();
const [recipes, userFavorites] = await Promise.all([
recipeLoader(),
getUserFavorites(fetch, locals, recipeLang),
locals.auth()
getUserFavorites(fetch, locals, recipeLang)
]);
return {