load photos filmstrip once at the section layout
Created by: jedmund
Summary
Architecture audit A-12 — dedupe the filmstrip fetch across the photos section.
Previously, every visit to /photos/[id] re-fetched /api/photos?limit=100 for the filmstrip navigation, even when clicking through from another photo in the same section. Grid (/photos) did its own separate 20-item DB query alongside.
Now:
- New
src/routes/photos/+layout.server.tsloads up to 100 photos once for the section and sets cache-control -
/photos/[id]readsphotoItemsfromawait parent()— no more per-navigation filmstrip fetch -
/photosgrid slices its first page from parent instead of issuing a duplicate query (and dropping its own header-set to avoid conflict with the layout)
Impact
- Grid entry: 1 DB query (unchanged)
- Detail entry (deep link): 1 DB + 1 API fetch (was 2 API fetches)
- Detail → detail navigation: 0 filmstrip refetches (was 1 per navigation) — the main win
Test plan
-
pnpm check— baseline 116 errors / 9 warnings, no new ones -
Visit /photos→ grid renders first 20 photos with correct pagination/hasMore -
Click a photo → detail view loads; filmstrip shows all photos -
Navigate photo → photo via filmstrip → no /api/photos?limit=100request in network tab -
Deep-link directly to /photos/[id]→ filmstrip populates from layout load -
Infinite scroll / "load more" on the grid still works