perf: drop all_brief fetch from favorites page
Favorites page fetched both /favorites/recipes and /items/all_brief, then
stitched isFavorite flags onto allRecipes so Search could filter across
the full catalogue. But Search is invoked with favoritesOnly={true} and
hideFavoritesFilter (so it's pinned on), so it only ever returns matches
that are already in the favorites list — allRecipes was dead weight.
- drop allRes / allRecipes / favoriteIds / allRecipesWithFavorites
- Search now receives data.favorites directly
- filteredFavorites filters data.favorites by matchedRecipeIds
- use locals.session ?? locals.auth() to reuse the hook's auth lookup
This commit is contained in:
@@ -7,7 +7,7 @@ Order = impact. Font items + app.html preload intentionally skipped.
|
||||
- [x] 1. Lucide subpath imports — convert `from '@lucide/svelte'` barrel imports to `@lucide/svelte/icons/<kebab-name>` so Vite tree-shakes per-icon (current 748 KB shared chunk)
|
||||
- [x] 2. Chart.js dynamic import in `FitnessChart.svelte` (drop 244 KB from non-stats fitness routes)
|
||||
- [x] 3. Recipe API endpoints — drop `JSON.parse(JSON.stringify(...))` double-serialize (9 endpoints). Client-side shuffle / cache headers deferred (would require rethinking hero preload + hydration)
|
||||
- [ ] 4. Favorites page — drop unnecessary `all_brief` fetch (verify consumer first)
|
||||
- [x] 4. Favorites page — drop unnecessary `all_brief` fetch (verified Search uses `favoritesOnly` so `allRecipes` was redundant)
|
||||
- [ ] 5. Replace redundant `locals.auth()` with `locals.session` across recipe/calendar/fitness loaders
|
||||
- [ ] 6. Stream fitness stats loader — return promises for slow panels
|
||||
- [ ] 7. Overview endpoint — add `.select(...)` projection, cap timeseries window
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "homepage",
|
||||
"version": "1.46.15",
|
||||
"version": "1.46.16",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, locals, params }) => {
|
||||
const apiBase = `/api/${params.recipeLang}`;
|
||||
const session = await locals.auth();
|
||||
const session = locals.session ?? await locals.auth();
|
||||
|
||||
if (!session?.user?.nickname) {
|
||||
const callbackUrl = encodeURIComponent(`/${params.recipeLang}/favorites`);
|
||||
@@ -11,43 +11,24 @@ export const load: PageServerLoad = async ({ fetch, locals, params }) => {
|
||||
}
|
||||
|
||||
try {
|
||||
const [res, allRes] = await Promise.all([
|
||||
fetch(`${apiBase}/favorites/recipes`),
|
||||
fetch(`${apiBase}/items/all_brief`)
|
||||
]);
|
||||
const res = await fetch(`${apiBase}/favorites/recipes`);
|
||||
|
||||
if (!res.ok) {
|
||||
return {
|
||||
favorites: [],
|
||||
allRecipes: [],
|
||||
error: 'Failed to load favorites'
|
||||
};
|
||||
}
|
||||
|
||||
const [favorites, allRecipes] = await Promise.all([res.json(), allRes.json()]);
|
||||
|
||||
// Mark all favorites with isFavorite flag for filter compatibility
|
||||
const favoritesWithFlag = favorites.map((recipe: any) => ({
|
||||
...recipe,
|
||||
isFavorite: true
|
||||
}));
|
||||
|
||||
// Get favorite IDs for marking in allRecipes
|
||||
const favoriteIds = new Set(favoritesWithFlag.map((r: any) => r._id));
|
||||
const allRecipesWithFavorites = allRecipes.map((recipe: any) => ({
|
||||
...recipe,
|
||||
isFavorite: favoriteIds.has(recipe._id)
|
||||
}));
|
||||
const favorites = await res.json();
|
||||
|
||||
return {
|
||||
favorites: favoritesWithFlag,
|
||||
allRecipes: allRecipesWithFavorites,
|
||||
favorites: favorites.map((recipe: any) => ({ ...recipe, isFavorite: true })),
|
||||
session
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
favorites: [],
|
||||
allRecipes: [],
|
||||
error: 'Failed to load favorites'
|
||||
};
|
||||
}
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
|
||||
function handleSearchResults(ids: Set<string>, categories: Set<string>) {
|
||||
matchedRecipeIds = ids;
|
||||
hasActiveSearch = ids.size < (data.allRecipes?.length || data.favorites.length);
|
||||
hasActiveSearch = ids.size < data.favorites.length;
|
||||
}
|
||||
|
||||
const filteredFavorites = $derived.by(() => {
|
||||
if (!hasActiveSearch) return data.favorites;
|
||||
return data.allRecipes.filter((r: any) => matchedRecipeIds.has(r._id));
|
||||
return data.favorites.filter((r: any) => matchedRecipeIds.has(r._id));
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -93,7 +93,7 @@
|
||||
|
||||
<p class="to-try-link"><a href="/{data.recipeLang}/to-try">{labels.toTry} →</a></p>
|
||||
|
||||
<Search favoritesOnly={true} lang={data.lang} recipes={data.allRecipes || data.favorites} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
|
||||
<Search favoritesOnly={true} lang={data.lang} recipes={data.favorites} isLoggedIn={!!data.session?.user} onSearchResults={handleSearchResults}></Search>
|
||||
|
||||
{#if data.error}
|
||||
<p class="empty-state">{labels.errorLoading} {data.error}</p>
|
||||
|
||||
Reference in New Issue
Block a user