Wrap more requests in React cache

This commit is contained in:
Sam Becker 2024-03-04 11:17:44 -06:00
parent a2fb8744d1
commit 0ccc9bb4cb
3 changed files with 8 additions and 5 deletions

View File

@ -12,7 +12,9 @@ import {
import PhotoDetailPage from '@/photo/PhotoDetailPage';
import { getPhotoCached } from '@/photo/cache';
import { getPhotosTagDataCached } from '@/tag/data';
import { ReactNode } from 'react';
import { ReactNode, cache } from 'react';
const getPhotoCachedCached = cache(getPhotoCached);
interface PhotoTagProps {
params: { photoId: string, tag: string }
@ -21,7 +23,7 @@ interface PhotoTagProps {
export async function generateMetadata({
params: { photoId, tag },
}: PhotoTagProps): Promise<Metadata> {
const photo = await getPhotoCached(photoId);
const photo = await getPhotoCachedCached(photoId);
if (!photo) { return {}; }
@ -52,7 +54,7 @@ export default async function PhotoTagPage({
params: { photoId, tag },
children,
}: PhotoTagProps & { children: ReactNode }) {
const photo = await getPhotoCached(photoId);
const photo = await getPhotoCachedCached(photoId);
if (!photo) { redirect(PATH_ROOT); }

View File

@ -134,6 +134,7 @@ export const getPhotosCached = (
getPhotos,
[KEY_PHOTOS, ...getPhotosCacheKeys(...args)],
)(...args).then(parseCachedPhotosDates);
export const getPhotosCachedCached = cache(getPhotosCached);
const getPhotosNearIdCached = (
...args: Parameters<typeof getPhotosNearId>

View File

@ -1,5 +1,5 @@
import {
getPhotosCached,
getPhotosCachedCached,
getPhotosTagMetaCached,
} from '@/photo/cache';
import {
@ -16,7 +16,7 @@ export const getPhotosTagDataCached = ({
limit?: number,
}) =>
Promise.all([
getPhotosCached({ tag, limit }),
getPhotosCachedCached({ tag, limit }),
getPhotosTagMetaCached(tag),
]);