From d97c3fcc369b8e6a5c5e1f240e991eb0396895d9 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Mon, 22 Jan 2024 20:27:54 -0600 Subject: [PATCH] Combine [photoId] static requests --- src/app/p/[photoId]/layout.tsx | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/app/p/[photoId]/layout.tsx b/src/app/p/[photoId]/layout.tsx index 26add48c..7c79fcda 100644 --- a/src/app/p/[photoId]/layout.tsx +++ b/src/app/p/[photoId]/layout.tsx @@ -1,5 +1,6 @@ import { GENERATE_STATIC_PARAMS_LIMIT, + GRID_THUMBNAILS_TO_SHOW_MAX, descriptionForPhoto, titleForPhoto, } from '@/photo'; @@ -11,10 +12,7 @@ import { absolutePathForPhotoImage, } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { - getPhotoCached, - // getPhotosNearIdCached, -} from '@/cache'; +import { getPhotosNearIdCached } from '@/cache'; import { getPhotoIds } from '@/services/vercel-postgres'; export async function generateStaticParams() { @@ -29,7 +27,12 @@ interface PhotoProps { export async function generateMetadata({ params: { photoId }, }:PhotoProps): Promise { - const photo = await getPhotoCached(photoId); + const photos = await getPhotosNearIdCached( + photoId, + GRID_THUMBNAILS_TO_SHOW_MAX + 2, + ); + + const photo = photos.find(p => p.id === photoId); if (!photo) { return {}; } @@ -60,31 +63,28 @@ export default async function PhotoPage({ params: { photoId }, children, }: PhotoProps & { children: React.ReactNode }) { - // const photos = await getPhotosNearIdCached( - // photoId, - // GRID_THUMBNAILS_TO_SHOW_MAX + 2, - // ); + const photos = await getPhotosNearIdCached( + photoId, + GRID_THUMBNAILS_TO_SHOW_MAX + 2, + ); - const photo = await getPhotoCached(photoId); - - // const photo = photos.find(p => p.id === photoId); + const photo = photos.find(p => p.id === photoId); if (!photo) { redirect(PATH_ROOT); } - // const isPhotoFirst = photos.findIndex(p => p.id === photoId) === 0; + const isPhotoFirst = photos.findIndex(p => p.id === photoId) === 0; return <> {children} ; }