From 4eacce7456eab1f6dc5ddebcd012f584e58f968b Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Sun, 6 Apr 2025 15:00:24 -0500 Subject: [PATCH] Cache photo meta queries --- app/admin/recipes/[recipe]/edit/page.tsx | 5 ++--- app/admin/tags/[tag]/edit/page.tsx | 5 ++--- app/feed/page.tsx | 5 +++-- app/focal/[focal]/[photoId]/page.tsx | 5 ++--- app/grid/page.tsx | 5 +++-- app/og/all/page.tsx | 5 ++--- app/page.tsx | 5 +++-- app/recipe/[recipe]/[photoId]/page.tsx | 5 ++--- app/tag/[tag]/[photoId]/page.tsx | 5 ++--- app/tag/hidden/[photoId]/page.tsx | 4 ++-- app/tag/hidden/page.tsx | 5 ++--- src/app/config.ts | 1 - 12 files changed, 25 insertions(+), 30 deletions(-) diff --git a/app/admin/recipes/[recipe]/edit/page.tsx b/app/admin/recipes/[recipe]/edit/page.tsx index 9565cc55..ff358d7b 100644 --- a/app/admin/recipes/[recipe]/edit/page.tsx +++ b/app/admin/recipes/[recipe]/edit/page.tsx @@ -1,9 +1,8 @@ import AdminChildPage from '@/components/AdminChildPage'; import { redirect } from 'next/navigation'; -import { getPhotosCached } from '@/photo/cache'; +import { getPhotosCached, getPhotosMetaCached } from '@/photo/cache'; import { PATH_ADMIN, PATH_ADMIN_RECIPES, pathForRecipe } from '@/app/paths'; import PhotoLightbox from '@/photo/PhotoLightbox'; -import { getPhotosMeta } from '@/photo/db/query'; import AdminRecipeBadge from '@/admin/AdminRecipeBadge'; import AdminRecipeForm from '@/admin/AdminRecipeForm'; import { getPhotoWithRecipeFromPhotos } from '@/recipe'; @@ -26,7 +25,7 @@ export default async function RecipePageEdit({ { count }, photos, ] = await Promise.all([ - getPhotosMeta({ recipe }), + getPhotosMetaCached({ recipe }), getPhotosCached({ recipe, limit: MAX_PHOTO_TO_SHOW }), ]); diff --git a/app/admin/tags/[tag]/edit/page.tsx b/app/admin/tags/[tag]/edit/page.tsx index 747dc180..b07ce24b 100644 --- a/app/admin/tags/[tag]/edit/page.tsx +++ b/app/admin/tags/[tag]/edit/page.tsx @@ -1,10 +1,9 @@ import AdminChildPage from '@/components/AdminChildPage'; import { redirect } from 'next/navigation'; -import { getPhotosCached } from '@/photo/cache'; +import { getPhotosCached, getPhotosMetaCached } from '@/photo/cache'; import AdminTagForm from '@/admin/AdminTagForm'; import { PATH_ADMIN, PATH_ADMIN_TAGS, pathForTag } from '@/app/paths'; import PhotoLightbox from '@/photo/PhotoLightbox'; -import { getPhotosMeta } from '@/photo/db/query'; import AdminTagBadge from '@/admin/AdminTagBadge'; const MAX_PHOTO_TO_SHOW = 6; @@ -24,7 +23,7 @@ export default async function PhotoPageEdit({ { count }, photos, ] = await Promise.all([ - getPhotosMeta({ tag }), + getPhotosMetaCached({ tag }), getPhotosCached({ tag, limit: MAX_PHOTO_TO_SHOW }), ]); diff --git a/app/feed/page.tsx b/app/feed/page.tsx index 98e6724d..318fe75e 100644 --- a/app/feed/page.tsx +++ b/app/feed/page.tsx @@ -5,8 +5,9 @@ import { import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { Metadata } from 'next/types'; import { cache } from 'react'; -import { getPhotos, getPhotosMeta } from '@/photo/db/query'; +import { getPhotos } from '@/photo/db/query'; import PhotoFeedPage from '@/photo/PhotoFeedPage'; +import { getPhotosMetaCached } from '@/photo/cache'; export const dynamic = 'force-static'; export const maxDuration = 60; @@ -28,7 +29,7 @@ export default async function FeedPage() { ] = await Promise.all([ getPhotosCached() .catch(() => []), - getPhotosMeta() + getPhotosMetaCached() .then(({ count }) => count) .catch(() => 0), ]); diff --git a/app/focal/[focal]/[photoId]/page.tsx b/app/focal/[focal]/[photoId]/page.tsx index 8c972a8c..69894b02 100644 --- a/app/focal/[focal]/[photoId]/page.tsx +++ b/app/focal/[focal]/[photoId]/page.tsx @@ -11,9 +11,8 @@ import { absolutePathForPhotoImage, } from '@/app/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotosNearIdCached } from '@/photo/cache'; +import { getPhotosNearIdCached, getPhotosMetaCached } from '@/photo/cache'; import { cache } from 'react'; -import { getPhotosMeta } from '@/photo/db/query'; import { getFocalLengthFromString } from '@/focal'; const getPhotosNearIdCachedCached = cache((photoId: string, focal: number) => @@ -72,7 +71,7 @@ export default async function PhotoFocalLengthPage({ if (!photo) { redirect(PATH_ROOT); } - const { count, dateRange } = await getPhotosMeta({ focal }); + const { count, dateRange } = await getPhotosMetaCached({ focal }); return ( []), - getPhotosMeta() + getPhotosMetaCached() .then(({ count }) => count) .catch(() => 0), getDataForCategoriesCached(), diff --git a/app/og/all/page.tsx b/app/og/all/page.tsx index 55791c14..fb16e074 100644 --- a/app/og/all/page.tsx +++ b/app/og/all/page.tsx @@ -2,8 +2,7 @@ import { INFINITE_SCROLL_GRID_INITIAL, INFINITE_SCROLL_GRID_MULTIPLE, } from '@/photo'; -import { getPhotosCached } from '@/photo/cache'; -import { getPhotosMeta } from '@/photo/db/query'; +import { getPhotosCached, getPhotosMetaCached } from '@/photo/cache'; import StaggeredOgPhotos from '@/photo/StaggeredOgPhotos'; import StaggeredOgPhotosInfinite from '@/photo/StaggeredOgPhotosInfinite'; @@ -14,7 +13,7 @@ export default async function OGPage() { ] = await Promise.all([ getPhotosCached({ limit: INFINITE_SCROLL_GRID_INITIAL }) .catch(() => []), - getPhotosMeta() + getPhotosMetaCached() .then(({ count }) => count) .catch(() => 0), ]); diff --git a/app/page.tsx b/app/page.tsx index 42df5c8e..67d33b21 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -6,12 +6,13 @@ import { import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { Metadata } from 'next/types'; import { cache } from 'react'; -import { getPhotos, getPhotosMeta } from '@/photo/db/query'; +import { getPhotos } from '@/photo/db/query'; import { GRID_HOMEPAGE_ENABLED } from '@/app/config'; import { NULL_CATEGORY_DATA } from '@/category/data'; import PhotoFeedPage from '@/photo/PhotoFeedPage'; import PhotoGridPage from '@/photo/PhotoGridPage'; import { getDataForCategoriesCached } from '@/category/cache'; +import { getPhotosMetaCached } from '@/photo/cache'; export const dynamic = 'force-static'; export const maxDuration = 60; @@ -35,7 +36,7 @@ export default async function HomePage() { ] = await Promise.all([ getPhotosCached() .catch(() => []), - getPhotosMeta() + getPhotosMetaCached() .then(({ count }) => count) .catch(() => 0), GRID_HOMEPAGE_ENABLED diff --git a/app/recipe/[recipe]/[photoId]/page.tsx b/app/recipe/[recipe]/[photoId]/page.tsx index 85d60dce..7caec133 100644 --- a/app/recipe/[recipe]/[photoId]/page.tsx +++ b/app/recipe/[recipe]/[photoId]/page.tsx @@ -11,9 +11,8 @@ import { absolutePathForPhotoImage, } from '@/app/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotosNearIdCached } from '@/photo/cache'; +import { getPhotosMetaCached, getPhotosNearIdCached } from '@/photo/cache'; import { cache } from 'react'; -import { getPhotosMeta } from '@/photo/db/query'; const getPhotosNearIdCachedCached = cache(( photoId: string, @@ -74,7 +73,7 @@ export default async function PhotoRecipePage({ if (!photo) { redirect(PATH_ROOT); } - const { count, dateRange } = await getPhotosMeta({ recipe }); + const { count, dateRange } = await getPhotosMetaCached({ recipe }); return ( getPhotosNearIdCached( @@ -71,7 +70,7 @@ export default async function PhotoTagPage({ if (!photo) { redirect(PATH_ROOT); } - const { count, dateRange } = await getPhotosMeta({ tag }); + const { count, dateRange } = await getPhotosMetaCached({ tag }); return (