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 PhotoDetailPage from '@/photo/PhotoDetailPage';
|
||||||
import { getPhotoCached } from '@/photo/cache';
|
import { getPhotoCached } from '@/photo/cache';
|
||||||
import { getPhotosTagDataCached } from '@/tag/data';
|
import { getPhotosTagDataCached } from '@/tag/data';
|
||||||
import { ReactNode } from 'react';
|
import { ReactNode, cache } from 'react';
|
||||||
|
|
||||||
|
const getPhotoCachedCached = cache(getPhotoCached);
|
||||||
|
|
||||||
interface PhotoTagProps {
|
interface PhotoTagProps {
|
||||||
params: { photoId: string, tag: string }
|
params: { photoId: string, tag: string }
|
||||||
@ -21,7 +23,7 @@ interface PhotoTagProps {
|
|||||||
export async function generateMetadata({
|
export async function generateMetadata({
|
||||||
params: { photoId, tag },
|
params: { photoId, tag },
|
||||||
}: PhotoTagProps): Promise<Metadata> {
|
}: PhotoTagProps): Promise<Metadata> {
|
||||||
const photo = await getPhotoCached(photoId);
|
const photo = await getPhotoCachedCached(photoId);
|
||||||
|
|
||||||
if (!photo) { return {}; }
|
if (!photo) { return {}; }
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ export default async function PhotoTagPage({
|
|||||||
params: { photoId, tag },
|
params: { photoId, tag },
|
||||||
children,
|
children,
|
||||||
}: PhotoTagProps & { children: ReactNode }) {
|
}: PhotoTagProps & { children: ReactNode }) {
|
||||||
const photo = await getPhotoCached(photoId);
|
const photo = await getPhotoCachedCached(photoId);
|
||||||
|
|
||||||
if (!photo) { redirect(PATH_ROOT); }
|
if (!photo) { redirect(PATH_ROOT); }
|
||||||
|
|
||||||
|
|||||||
@ -134,6 +134,7 @@ export const getPhotosCached = (
|
|||||||
getPhotos,
|
getPhotos,
|
||||||
[KEY_PHOTOS, ...getPhotosCacheKeys(...args)],
|
[KEY_PHOTOS, ...getPhotosCacheKeys(...args)],
|
||||||
)(...args).then(parseCachedPhotosDates);
|
)(...args).then(parseCachedPhotosDates);
|
||||||
|
export const getPhotosCachedCached = cache(getPhotosCached);
|
||||||
|
|
||||||
const getPhotosNearIdCached = (
|
const getPhotosNearIdCached = (
|
||||||
...args: Parameters<typeof getPhotosNearId>
|
...args: Parameters<typeof getPhotosNearId>
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
getPhotosCached,
|
getPhotosCachedCached,
|
||||||
getPhotosTagMetaCached,
|
getPhotosTagMetaCached,
|
||||||
} from '@/photo/cache';
|
} from '@/photo/cache';
|
||||||
import {
|
import {
|
||||||
@ -16,7 +16,7 @@ export const getPhotosTagDataCached = ({
|
|||||||
limit?: number,
|
limit?: number,
|
||||||
}) =>
|
}) =>
|
||||||
Promise.all([
|
Promise.all([
|
||||||
getPhotosCached({ tag, limit }),
|
getPhotosCachedCached({ tag, limit }),
|
||||||
getPhotosTagMetaCached(tag),
|
getPhotosTagMetaCached(tag),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user