diff --git a/src/app/(auth-state)/admin/photos/[photoId]/edit/page.tsx b/src/app/(auth-state)/admin/photos/[photoId]/edit/page.tsx index 056cb2ad..a6589ac9 100644 --- a/src/app/(auth-state)/admin/photos/[photoId]/edit/page.tsx +++ b/src/app/(auth-state)/admin/photos/[photoId]/edit/page.tsx @@ -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'); } diff --git a/src/app/(auth-state)/admin/photos/page.tsx b/src/app/(auth-state)/admin/photos/page.tsx index 3f991668..b2949403 100644 --- a/src/app/(auth-state)/admin/photos/page.tsx +++ b/src/app/(auth-state)/admin/photos/page.tsx @@ -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() : [], ]); diff --git a/src/services/postgres.ts b/src/services/postgres.ts index 43894af9..e63d38e7 100644 --- a/src/services/postgres.ts +++ b/src/services/postgres.ts @@ -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)); };