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] 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] 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)
|
- [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
|
- [ ] 5. Replace redundant `locals.auth()` with `locals.session` across recipe/calendar/fitness loaders
|
||||||
- [ ] 6. Stream fitness stats loader — return promises for slow panels
|
- [ ] 6. Stream fitness stats loader — return promises for slow panels
|
||||||
- [ ] 7. Overview endpoint — add `.select(...)` projection, cap timeseries window
|
- [ ] 7. Overview endpoint — add `.select(...)` projection, cap timeseries window
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "homepage",
|
"name": "homepage",
|
||||||
"version": "1.46.15",
|
"version": "1.46.16",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { redirect } from '@sveltejs/kit';
|
|||||||
|
|
||||||
export const load: PageServerLoad = async ({ fetch, locals, params }) => {
|
export const load: PageServerLoad = async ({ fetch, locals, params }) => {
|
||||||
const apiBase = `/api/${params.recipeLang}`;
|
const apiBase = `/api/${params.recipeLang}`;
|
||||||
const session = await locals.auth();
|
const session = locals.session ?? await locals.auth();
|
||||||
|
|
||||||
if (!session?.user?.nickname) {
|
if (!session?.user?.nickname) {
|
||||||
const callbackUrl = encodeURIComponent(`/${params.recipeLang}/favorites`);
|
const callbackUrl = encodeURIComponent(`/${params.recipeLang}/favorites`);
|
||||||
@@ -11,44 +11,25 @@ export const load: PageServerLoad = async ({ fetch, locals, params }) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [res, allRes] = await Promise.all([
|
const res = await fetch(`${apiBase}/favorites/recipes`);
|
||||||
fetch(`${apiBase}/favorites/recipes`),
|
|
||||||
fetch(`${apiBase}/items/all_brief`)
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
return {
|
return {
|
||||||
favorites: [],
|
favorites: [],
|
||||||
allRecipes: [],
|
|
||||||
error: 'Failed to load favorites'
|
error: 'Failed to load favorites'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const [favorites, allRecipes] = await Promise.all([res.json(), allRes.json()]);
|
const favorites = await res.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)
|
|
||||||
}));
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
favorites: favoritesWithFlag,
|
favorites: favorites.map((recipe: any) => ({ ...recipe, isFavorite: true })),
|
||||||
allRecipes: allRecipesWithFavorites,
|
|
||||||
session
|
session
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
favorites: [],
|
favorites: [],
|
||||||
allRecipes: [],
|
|
||||||
error: 'Failed to load favorites'
|
error: 'Failed to load favorites'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -33,12 +33,12 @@
|
|||||||
|
|
||||||
function handleSearchResults(ids: Set<string>, categories: Set<string>) {
|
function handleSearchResults(ids: Set<string>, categories: Set<string>) {
|
||||||
matchedRecipeIds = ids;
|
matchedRecipeIds = ids;
|
||||||
hasActiveSearch = ids.size < (data.allRecipes?.length || data.favorites.length);
|
hasActiveSearch = ids.size < data.favorites.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
const filteredFavorites = $derived.by(() => {
|
const filteredFavorites = $derived.by(() => {
|
||||||
if (!hasActiveSearch) return data.favorites;
|
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>
|
</script>
|
||||||
|
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
|
|
||||||
<p class="to-try-link"><a href="/{data.recipeLang}/to-try">{labels.toTry} →</a></p>
|
<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}
|
{#if data.error}
|
||||||
<p class="empty-state">{labels.errorLoading} {data.error}</p>
|
<p class="empty-state">{labels.errorLoading} {data.error}</p>
|
||||||
|
|||||||
Reference in New Issue
Block a user