diff --git a/src/app/(auth-state)/admin/photos/page.tsx b/src/app/(auth-state)/admin/photos/page.tsx index 2521b796..3f991668 100644 --- a/src/app/(auth-state)/admin/photos/page.tsx +++ b/src/app/(auth-state)/admin/photos/page.tsx @@ -37,18 +37,16 @@ export default async function AdminPage({ photos, count, blobUploadUrls, + blobPhotoUrls, ] = await Promise.all([ - await getPhotos({ sortBy: 'createdAt', limit }), - await getPhotosCount(), - await getBlobUploadUrls(), + getPhotos({ sortBy: 'createdAt', limit }), + getPhotosCount(), + getBlobUploadUrls(), + DEBUG_PHOTO_BLOBS ? getBlobPhotoUrls() : [], ]); const showMorePhotos = count > photos.length; - const blobPhotoUrls = DEBUG_PHOTO_BLOBS - ? await getBlobPhotoUrls() - : []; - return ( photos.length; diff --git a/src/app/(static)/home-image/route.tsx b/src/app/(static)/home-image/route.tsx index 564d5932..3e1288af 100644 --- a/src/app/(static)/home-image/route.tsx +++ b/src/app/(static)/home-image/route.tsx @@ -10,11 +10,13 @@ import { ImageResponse } from 'next/server'; export const runtime = 'edge'; export async function GET(request: Request) { - const photos = await getPhotosCached({ - limit: MAX_PHOTOS_TO_SHOW_HOME, - }); - - const headers = await getImageCacheHeadersForAuth(await auth()); + const [ + photos, + headers, + ] = await Promise.all([ + getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_HOME }), + getImageCacheHeadersForAuth(await auth()), + ]); const { width, height } = IMAGE_OG_SMALL_SIZE; diff --git a/src/app/(static)/og/page.tsx b/src/app/(static)/og/page.tsx index d5d22e3d..49181620 100644 --- a/src/app/(static)/og/page.tsx +++ b/src/app/(static)/og/page.tsx @@ -12,9 +12,13 @@ export default async function GridPage({ }) { const { offset, limit } = getPhotosLimitForQuery(searchParams.next); - const photos = await getPhotosCached({ limit }); - - const count = await getPhotosCountCached(); + const [ + photos, + count, + ] = await Promise.all([ + getPhotosCached({ limit }), + getPhotosCountCached(), + ]); const showMorePhotos = count > photos.length; diff --git a/src/app/(static)/p/[photoId]/image/route.tsx b/src/app/(static)/p/[photoId]/image/route.tsx index 282fd7c3..a0bf138b 100644 --- a/src/app/(static)/p/[photoId]/image/route.tsx +++ b/src/app/(static)/p/[photoId]/image/route.tsx @@ -8,14 +8,15 @@ import { ImageResponse } from 'next/server'; export const runtime = 'edge'; export async function GET(request: Request, context: any){ - const photo = await getPhotoCached(context.params.photoId); - - const { - fontFamily, - fonts, - } = await getIBMPlexMonoMedium(); - - const headers = await getImageCacheHeadersForAuth(await auth()); + const [ + photo, + { fontFamily, fonts }, + headers, + ] = await Promise.all([ + getPhotoCached(context.params.photoId), + getIBMPlexMonoMedium(), + getImageCacheHeadersForAuth(await auth()), + ]); if (!photo) { return new Response('Photo not found', { status: 404 }); } diff --git a/src/app/(static)/page.tsx b/src/app/(static)/page.tsx index 41467ea0..2fcb8570 100644 --- a/src/app/(static)/page.tsx +++ b/src/app/(static)/page.tsx @@ -21,10 +21,14 @@ export default async function HomePage({ }) { const { offset, limit } = getPhotosLimitForQuery(searchParams.next, 12); - const photos = await getPhotosCached({ limit }); - - const count = await getPhotosCountCached(); - + const [ + photos, + count, + ] = await Promise.all([ + getPhotosCached({ limit }), + getPhotosCountCached(), + ]); + const showMorePhotos = count > photos.length; return ( diff --git a/src/app/(static)/t/[tag]/image/route.tsx b/src/app/(static)/t/[tag]/image/route.tsx index c09e98c3..7bcdd4cf 100644 --- a/src/app/(static)/t/[tag]/image/route.tsx +++ b/src/app/(static)/t/[tag]/image/route.tsx @@ -11,17 +11,18 @@ import { ImageResponse } from 'next/server'; export const runtime = 'edge'; export async function GET(request: Request, context: any) { - const photos = await getPhotosCached({ - limit: MAX_PHOTOS_TO_SHOW_PER_TAG, - tag: context.params.tag, - }); - - const { - fontFamily, - fonts, - } = await getIBMPlexMonoMedium(); - - const headers = await getImageCacheHeadersForAuth(await auth()); + const [ + photos, + { fontFamily, fonts }, + headers, + ] = await Promise.all([ + getPhotosCached({ + limit: MAX_PHOTOS_TO_SHOW_PER_TAG, + tag: context.params.tag, + }), + getIBMPlexMonoMedium(), + getImageCacheHeadersForAuth(await auth()), + ]); const { width, height } = IMAGE_OG_SMALL_SIZE; diff --git a/src/app/(static)/template-image-tight/route.tsx b/src/app/(static)/template-image-tight/route.tsx index 9183818a..45007afe 100644 --- a/src/app/(static)/template-image-tight/route.tsx +++ b/src/app/(static)/template-image-tight/route.tsx @@ -12,17 +12,18 @@ import { ImageResponse } from 'next/server'; export const runtime = 'edge'; export async function GET(request: Request) { - const photos = await getPhotosCached({ - sortBy: 'priority', - limit: MAX_PHOTOS_TO_SHOW_TEMPLATE_TIGHT, - }); - - const { - fontFamily, - fonts, - } = await getIBMPlexMonoMedium(); - - const headers = await getImageCacheHeadersForAuth(await auth()); + const [ + photos, + { fontFamily, fonts }, + headers, + ] = await Promise.all([ + getPhotosCached({ + sortBy: 'priority', + limit: MAX_PHOTOS_TO_SHOW_TEMPLATE_TIGHT, + }), + getIBMPlexMonoMedium(), + getImageCacheHeadersForAuth(await auth()), + ]); const { width, height } = IMAGE_OG_SIZE; diff --git a/src/app/(static)/template-image/route.tsx b/src/app/(static)/template-image/route.tsx index cfbdfc0e..101b39b4 100644 --- a/src/app/(static)/template-image/route.tsx +++ b/src/app/(static)/template-image/route.tsx @@ -12,17 +12,15 @@ import { ImageResponse } from 'next/server'; export const runtime = 'edge'; export async function GET(request: Request) { - const photos = await getPhotosCached({ - sortBy: 'priority', - limit: MAX_PHOTOS_TO_SHOW_TEMPLATE, - }); - - const { - fontFamily, - fonts, - } = await getIBMPlexMonoMedium(); - - const headers = await getImageCacheHeadersForAuth(await auth()); + const [ + photos, + { fontFamily, fonts }, + headers, + ] = await Promise.all([ + getPhotosCached({ sortBy: 'priority', limit: MAX_PHOTOS_TO_SHOW_TEMPLATE }), + getIBMPlexMonoMedium(), + getImageCacheHeadersForAuth(await auth()), + ]); const { width, height } = GRID_OG_SIZE; diff --git a/src/cache/index.ts b/src/cache/index.ts index 0ac85e74..3c7e43c1 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -74,7 +74,7 @@ export const getUniqueTagsCached: typeof getUniqueTags = (...args) => } )(); -export const getImageCacheHeadersForAuth = async (session?: Session) => { +export const getImageCacheHeadersForAuth = (session?: Session) => { return { 'Cache-Control': !session?.user ? 's-maxage=3600, stale-while-revalidate=59' diff --git a/src/photo/actions.ts b/src/photo/actions.ts index 490f266a..52e87c33 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -23,6 +23,7 @@ export async function createPhotoAction(formData: FormData) { ); if (updatedUrl) { photo.url = updatedUrl; } + await sqlInsertPhotoIntoDb(photo); revalidatePhotosTag(); @@ -41,8 +42,10 @@ export async function updatePhotoAction(formData: FormData) { } export async function deletePhotoAction(formData: FormData) { - await deleteBlobPhoto(formData.get('url') as string); - await sqlDeletePhoto(formData.get('id') as string); + await Promise.all([ + deleteBlobPhoto(formData.get('url') as string), + sqlDeletePhoto(formData.get('id') as string), + ]); revalidatePhotosTag(); };