diff --git a/src/app/p/[photoId]/layout.tsx b/src/app/p/[photoId]/layout.tsx index 974ef37e..1dce6b7f 100644 --- a/src/app/p/[photoId]/layout.tsx +++ b/src/app/p/[photoId]/layout.tsx @@ -13,14 +13,13 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached, getPhotosNearIdCached } from '@/cache'; -import { getPhotos } from '@/services/vercel-postgres'; +import { getPhotoIds } from '@/services/vercel-postgres'; export async function generateStaticParams() { - const photos = await getPhotos({ limit: GENERATE_STATIC_PARAMS_LIMIT }); - return photos.map(({ id }) => ({ photoId: id })); + const photos = await getPhotoIds({ limit: GENERATE_STATIC_PARAMS_LIMIT }); + return photos.map(id => ({ photoId: id })); } - interface PhotoProps { params: { photoId: string } } diff --git a/src/services/vercel-postgres.ts b/src/services/vercel-postgres.ts index 5e68abf4..d525a5eb 100644 --- a/src/services/vercel-postgres.ts +++ b/src/services/vercel-postgres.ts @@ -410,6 +410,13 @@ export const getPhotosNearId = async ( .then(({ rows }) => rows.map(parsePhotoFromDb)); }; +export const getPhotoIds = async ({ limit }: { limit?: number }) => { + return safelyQueryPhotos(() => limit + ? sql`SELECT id FROM photos LIMIT ${limit}` + : sql`SELECT id FROM photos`) + .then(({ rows }) => rows.map(({ id }) => id as string)); +}; + export const getPhoto = async (id: string): Promise => { // Check for photo id forwarding // and convert short ids to uuids