Cache admin sql requests
This commit is contained in:
parent
d20dce5053
commit
907561d1fa
@ -1,8 +1,8 @@
|
|||||||
import PhotoForm from '@/photo/PhotoForm';
|
import PhotoForm from '@/photo/PhotoForm';
|
||||||
import { convertPhotoToFormData } from '@/photo/form';
|
import { convertPhotoToFormData } from '@/photo/form';
|
||||||
import AdminChildPage from '@/components/AdminChildPage';
|
import AdminChildPage from '@/components/AdminChildPage';
|
||||||
import { getPhoto } from '@/services/postgres';
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
import { getPhotoCached } from '@/cache';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
@ -11,7 +11,7 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function PhotoPageEdit({ params: { photoId } }: Props) {
|
export default async function PhotoPageEdit({ params: { photoId } }: Props) {
|
||||||
const photo = await getPhoto(photoId);
|
const photo = await getPhotoCached(photoId);
|
||||||
|
|
||||||
if (!photo) { redirect('/admin'); }
|
if (!photo) { redirect('/admin'); }
|
||||||
|
|
||||||
|
|||||||
@ -17,10 +17,10 @@ import {
|
|||||||
getBlobPhotoUrls,
|
getBlobPhotoUrls,
|
||||||
getBlobUploadUrls,
|
getBlobUploadUrls,
|
||||||
} from '@/services/blob';
|
} from '@/services/blob';
|
||||||
import { getPhotos, getPhotosCount } from '@/services/postgres';
|
|
||||||
import { pathForPhoto, pathForPhotoEdit } from '@/site/paths';
|
import { pathForPhoto, pathForPhotoEdit } from '@/site/paths';
|
||||||
import { getPhotosLimitForQuery, titleForPhoto } from '@/photo';
|
import { getPhotosLimitForQuery, titleForPhoto } from '@/photo';
|
||||||
import MorePhotos from '@/components/MorePhotos';
|
import MorePhotos from '@/components/MorePhotos';
|
||||||
|
import { getPhotosCached, getPhotosCountCached } from '@/cache';
|
||||||
|
|
||||||
export const runtime = 'edge';
|
export const runtime = 'edge';
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ export default async function AdminPage({
|
|||||||
blobUploadUrls,
|
blobUploadUrls,
|
||||||
blobPhotoUrls,
|
blobPhotoUrls,
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
getPhotos({ sortBy: 'createdAt', limit }),
|
getPhotosCached({ sortBy: 'createdAt', limit }),
|
||||||
getPhotosCount(),
|
getPhotosCountCached(),
|
||||||
getBlobUploadUrls(),
|
getBlobUploadUrls(),
|
||||||
DEBUG_PHOTO_BLOBS ? getBlobPhotoUrls() : [],
|
DEBUG_PHOTO_BLOBS ? getBlobPhotoUrls() : [],
|
||||||
]);
|
]);
|
||||||
|
|||||||
@ -251,7 +251,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => {
|
|||||||
takenAfterInclusive,
|
takenAfterInclusive,
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
const getPhotosRequest = takenBefore
|
const getPhotosSql = takenBefore
|
||||||
? () => sqlGetPhotosTakenBeforeDate(takenBefore, limit)
|
? () => sqlGetPhotosTakenBeforeDate(takenBefore, limit)
|
||||||
: takenAfterInclusive
|
: takenAfterInclusive
|
||||||
? () => sqlGetPhotosTakenAfterDateInclusive(takenAfterInclusive, limit)
|
? () => sqlGetPhotosTakenAfterDateInclusive(takenAfterInclusive, limit)
|
||||||
@ -263,7 +263,7 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => {
|
|||||||
? () => sqlGetPhotosSortedByPriority(limit, offset)
|
? () => sqlGetPhotosSortedByPriority(limit, offset)
|
||||||
: () => sqlGetPhotos(limit, offset);
|
: () => sqlGetPhotos(limit, offset);
|
||||||
|
|
||||||
return safelyQueryPhotos(() => getPhotosRequest())
|
return safelyQueryPhotos(getPhotosSql)
|
||||||
.then(({ rows }) => rows.map(parsePhotoFromDb));
|
.then(({ rows }) => rows.map(parsePhotoFromDb));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user