Wrap more requests in React cache
This commit is contained in:
parent
a2fb8744d1
commit
0ccc9bb4cb
@ -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); }
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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),
|
||||
]);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user