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