From 66e5ec3a458fc3eb5d2a739d35979b807f4e36dc Mon Sep 17 00:00:00 2001 From: ilia Date: Tue, 4 Aug 2026 21:34:23 -0400 Subject: [PATCH] Slim gallery face payloads for home SSR and search API. Grid only needs location + person names; drop landmarks/pose/detector fields. --- viewer-frontend/app/api/search/route.ts | 34 ++---------------------- viewer-frontend/app/page.tsx | 35 ++----------------------- viewer-frontend/lib/grid-face-select.ts | 21 +++++++++++++++ 3 files changed, 25 insertions(+), 65 deletions(-) create mode 100644 viewer-frontend/lib/grid-face-select.ts diff --git a/viewer-frontend/app/api/search/route.ts b/viewer-frontend/app/api/search/route.ts index b4d54eb..828e7b2 100644 --- a/viewer-frontend/app/api/search/route.ts +++ b/viewer-frontend/app/api/search/route.ts @@ -3,6 +3,7 @@ import { prisma, prismaAuth } from '@/lib/db'; import { serializePhotos } from '@/lib/serialize'; import { auth } from '@/app/api/auth/[...nextauth]/route'; import { photoIdsMatchingAll } from '@/lib/search-filter-sql'; +import { gridFaceSelect } from '@/lib/grid-face-select'; export async function GET(request: NextRequest) { try { @@ -265,38 +266,7 @@ export async function GET(request: NextRequest) { try { faces = await prisma.face.findMany({ where: { photo_id: { in: photoIds } }, - select: { - id: true, - photo_id: true, - person_id: true, - location: true, - confidence: true, - quality_score: true, - is_primary_encoding: true, - detector_backend: true, - model_name: true, - face_confidence: true, - exif_orientation: true, - pose_mode: true, - yaw_angle: true, - pitch_angle: true, - roll_angle: true, - landmarks: true, - identified_by_user_id: true, - excluded: true, - Person: { - select: { - id: true, - first_name: true, - last_name: true, - middle_name: true, - maiden_name: true, - date_of_birth: true, - created_date: true, - }, - }, - // Exclude encoding field (Bytes) to avoid P2023 conversion errors - }, + select: gridFaceSelect, }); } catch (faceError: any) { if (faceError?.code === 'P2023' || faceError?.message?.includes('Conversion failed')) { diff --git a/viewer-frontend/app/page.tsx b/viewer-frontend/app/page.tsx index 4a0acce..5baca89 100644 --- a/viewer-frontend/app/page.tsx +++ b/viewer-frontend/app/page.tsx @@ -1,8 +1,8 @@ import { Suspense } from 'react'; import { prisma } from '@/lib/db'; import { HomePageContent } from './HomePageContent'; -import { Photo } from '@prisma/client'; import { serializePhotos, serializePeople, serializeTags } from '@/lib/serialize'; +import { gridFaceSelect } from '@/lib/grid-face-select'; // Force dynamic rendering to prevent database queries during build export const dynamic = 'force-dynamic'; @@ -171,38 +171,7 @@ export default async function HomePage() { const photoIds = photosBase.map(p => p.id); const faces = await prisma.face.findMany({ where: { photo_id: { in: photoIds } }, - select: { - id: true, - photo_id: true, - person_id: true, - location: true, - confidence: true, - quality_score: true, - is_primary_encoding: true, - detector_backend: true, - model_name: true, - face_confidence: true, - exif_orientation: true, - pose_mode: true, - yaw_angle: true, - pitch_angle: true, - roll_angle: true, - landmarks: true, - identified_by_user_id: true, - excluded: true, - Person: { - select: { - id: true, - first_name: true, - last_name: true, - middle_name: true, - maiden_name: true, - date_of_birth: true, - created_date: true, - }, - }, - // Exclude encoding field (Bytes) to avoid P2023 conversion errors - }, + select: gridFaceSelect, }); // Combine the data manually diff --git a/viewer-frontend/lib/grid-face-select.ts b/viewer-frontend/lib/grid-face-select.ts new file mode 100644 index 0000000..76b5298 --- /dev/null +++ b/viewer-frontend/lib/grid-face-select.ts @@ -0,0 +1,21 @@ +/** + * Minimal face fields for gallery grid (tooltips / hover names only). + * Avoids loading landmarks, pose, detector metadata on every home/search request. + */ +export const gridFaceSelect = { + id: true, + photo_id: true, + person_id: true, + location: true, + Person: { + select: { + id: true, + first_name: true, + last_name: true, + middle_name: true, + maiden_name: true, + date_of_birth: true, + created_date: true, + }, + }, +} as const;