Make sure photo page queries are cached

This commit is contained in:
Sam Becker 2024-04-26 18:51:32 -05:00
parent edb4df83b8
commit 1ea7f2f9ac

View File

@ -12,11 +12,9 @@ import {
absolutePathForPhotoImage, absolutePathForPhotoImage,
} from '@/site/paths'; } from '@/site/paths';
import PhotoDetailPage from '@/photo/PhotoDetailPage'; import PhotoDetailPage from '@/photo/PhotoDetailPage';
import { getPhotoIds, getPhotosNearId } from '@/services/vercel-postgres'; import { getPhotoIds } from '@/services/vercel-postgres';
import { STATICALLY_OPTIMIZED } from '@/site/config'; import { STATICALLY_OPTIMIZED } from '@/site/config';
import { cache } from 'react'; import { getPhotosNearIdCachedCached } from '@/photo/cache';
const getPhotosNearIdCached = cache(getPhotosNearId);
export let generateStaticParams: export let generateStaticParams:
(() => Promise<{ photoId: string }[]>) | undefined = undefined; (() => Promise<{ photoId: string }[]>) | undefined = undefined;
@ -35,7 +33,7 @@ interface PhotoProps {
export async function generateMetadata({ export async function generateMetadata({
params: { photoId }, params: { photoId },
}:PhotoProps): Promise<Metadata> { }:PhotoProps): Promise<Metadata> {
const { photo } = await getPhotosNearIdCached( const { photo } = await getPhotosNearIdCachedCached(
photoId, photoId,
GRID_THUMBNAILS_TO_SHOW_MAX + 2, GRID_THUMBNAILS_TO_SHOW_MAX + 2,
); );
@ -69,7 +67,7 @@ export default async function PhotoPage({
params: { photoId }, params: { photoId },
children, children,
}: PhotoProps & { children: React.ReactNode }) { }: PhotoProps & { children: React.ReactNode }) {
const { photos, photo } = await getPhotosNearIdCached( const { photos, photo } = await getPhotosNearIdCachedCached(
photoId, photoId,
GRID_THUMBNAILS_TO_SHOW_MAX + 2, GRID_THUMBNAILS_TO_SHOW_MAX + 2,
); );