mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-09-18 19:42:04 +00:00
acaf760b36
The server load fetched a full combined-data page at a 9999 item page size, carrying detail text and ownership fields the grid never renders, and the client re-fetched the same payload after hydration. Load a trimmed grid row instead and pack it as positional tuples so field names are not repeated for every one of a thousand-plus entries. Entry detail is fetched on demand from the new per-entry endpoint when a cell is opened, and the grid marks itself interactive so other page-start work can queue behind it.
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { packGrid } from '$lib/models/PokedexGridRow';
|
|
import { error, redirect } from '@sveltejs/kit';
|
|
import PokedexRepository from '$lib/repositories/PokedexRepository';
|
|
import { loadPokedexGrid } from '$lib/services/PokedexGridService';
|
|
import { PokedexPerformance } from '$lib/server/pokedexPerformance';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ locals, params, setHeaders, cookies }) => {
|
|
const timings = new PokedexPerformance();
|
|
const { session, user } = await timings.measure('auth', () => locals.safeGetSession());
|
|
if (!session || !user) throw redirect(303, '/signin');
|
|
const pokedex = await timings.measure('ownership', () =>
|
|
new PokedexRepository(locals.supabase, user.id).findById(params.id)
|
|
);
|
|
if (!pokedex) throw error(404, 'Pokédex not found');
|
|
let grid = null;
|
|
try {
|
|
grid = await loadPokedexGrid(locals.supabase, user.id, pokedex, timings);
|
|
} catch {
|
|
console.error('Unable to load Pokédex grid');
|
|
}
|
|
const packed = timings.prepare(() => (grid ? packGrid(grid) : null));
|
|
timings.recordAuth(locals.pokedexAuthMs);
|
|
const timing = timings.finish();
|
|
setHeaders({
|
|
'cache-control': 'private, no-store',
|
|
...(timing ? { 'server-timing': timing } : {})
|
|
});
|
|
const layout = cookies.get('boxViewLayout');
|
|
const boxViewLayout: 'comfortable' | 'compact' | 'ultra' =
|
|
layout === 'compact' || layout === 'ultra' ? layout : 'comfortable';
|
|
return { pokedex, grid: packed, boxViewLayout };
|
|
};
|