Cache photo meta queries

This commit is contained in:
Sam Becker 2025-04-06 15:00:24 -05:00
parent 2ce07492ed
commit 4eacce7456
12 changed files with 25 additions and 30 deletions

View File

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

View File

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

View File

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

View File

@ -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 (
<PhotoDetailPage {...{

View File

@ -4,10 +4,11 @@ import {
} from '@/photo';
import PhotosEmptyState from '@/photo/PhotosEmptyState';
import { Metadata } from 'next/types';
import { getPhotos, getPhotosMeta } from '@/photo/db/query';
import { getPhotos } from '@/photo/db/query';
import { cache } from 'react';
import PhotoGridPage from '@/photo/PhotoGridPage';
import { getDataForCategoriesCached } from '@/category/cache';
import { getPhotosMetaCached } from '@/photo/cache';
export const dynamic = 'force-static';
@ -29,7 +30,7 @@ export default async function GridPage() {
] = await Promise.all([
getPhotosCached()
.catch(() => []),
getPhotosMeta()
getPhotosMetaCached()
.then(({ count }) => count)
.catch(() => 0),
getDataForCategoriesCached(),

View File

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

View File

@ -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

View File

@ -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 (
<PhotoDetailPage {...{

View File

@ -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, tag: string) =>
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 (
<PhotoDetailPage {...{

View File

@ -5,9 +5,9 @@ import {
} from '@/photo';
import PhotoDetailPage from '@/photo/PhotoDetailPage';
import {
getPhotosMetaCached,
getPhotosNearIdCached,
} from '@/photo/cache';
import { getPhotosMeta } from '@/photo/db/query';
import { PATH_ROOT, absolutePathForPhoto } from '@/app/paths';
import { TAG_HIDDEN } from '@/tag';
import { Metadata } from 'next';
@ -63,7 +63,7 @@ export default async function PhotoTagHiddenPage({
if (!photo) { redirect(PATH_ROOT); }
const { count, dateRange } = await getPhotosMeta({ hidden: 'only' });
const { count, dateRange } = await getPhotosMetaCached({ hidden: 'only' });
return (
<PhotoDetailPage {...{

View File

@ -2,8 +2,7 @@ import AnimateItems from '@/components/AnimateItems';
import Note from '@/components/Note';
import AppGrid from '@/components/AppGrid';
import PhotoGrid from '@/photo/PhotoGrid';
import { getPhotosNoStore } from '@/photo/cache';
import { getPhotosMeta } from '@/photo/db/query';
import { getPhotosMetaCached, getPhotosNoStore } from '@/photo/cache';
import { absolutePathForTag } from '@/app/paths';
import { TAG_HIDDEN, descriptionForTaggedPhotos, titleForTag } from '@/tag';
import HiddenHeader from '@/tag/HiddenHeader';
@ -11,7 +10,7 @@ import { Metadata } from 'next';
import { cache } from 'react';
const getPhotosHiddenMetaCached = cache(() =>
getPhotosMeta({ hidden: 'only' }));
getPhotosMetaCached({ hidden: 'only' }));
export async function generateMetadata(): Promise<Metadata> {
const { count, dateRange } = await getPhotosHiddenMetaCached();

View File

@ -299,7 +299,6 @@ export const ADMIN_DEBUG_TOOLS_ENABLED = process.env.ADMIN_DEBUG_TOOLS === '1';
export const ADMIN_DB_OPTIMIZE_ENABLED = process.env.ADMIN_DB_OPTIMIZE === '1';
export const ADMIN_SQL_DEBUG_ENABLED =
process.env.ADMIN_SQL_DEBUG === '1';
// && !IS_BUILDING;
export const APP_CONFIGURATION = {
// Storage