Refine static params queries
This commit is contained in:
parent
4887f93bfc
commit
84848f6a45
@ -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 }
|
||||
}
|
||||
|
||||
@ -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<Photo | undefined> => {
|
||||
// Check for photo id forwarding
|
||||
// and convert short ids to uuids
|
||||
|
||||
Loading…
Reference in New Issue
Block a user