Cache admin sql requests

This commit is contained in:
Sam Becker 2023-09-22 23:23:19 -05:00
parent d20dce5053
commit 907561d1fa
3 changed files with 7 additions and 7 deletions

View File

@ -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'); }

View File

@ -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() : [],
]);

View File

@ -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));
};