diff --git a/src/app/(static)/p/[photoId]/layout.tsx b/src/app/(static)/p/[photoId]/layout.tsx index 1664732b..24a7dea0 100644 --- a/src/app/(static)/p/[photoId]/layout.tsx +++ b/src/app/(static)/p/[photoId]/layout.tsx @@ -12,6 +12,7 @@ import { } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; import { getPhotoCached, getPhotosCached } from '@/cache'; +import { PRIORITY_ORDER_ENABLED } from '@/site/config'; interface PhotoProps { params: { photoId: string } @@ -60,9 +61,16 @@ export default async function PhotoPage({ photosBefore, photosAfter, ] = await Promise.all([ - getPhotosCached({ takenBefore: photo.takenAt, limit: 1 }), getPhotosCached({ - takenAfterInclusive: photo.takenAt, + ...(PRIORITY_ORDER_ENABLED && photo.priorityOrder !== undefined) + ? { beforePriorityOrder: photo.priorityOrder } + : { takenBefore: photo.takenAt }, + limit: 1, + }), + getPhotosCached({ + ...(PRIORITY_ORDER_ENABLED && photo.priorityOrder !== undefined) + ? { afterPriorityOrderInclusive: photo.priorityOrder } + : { takenAfterInclusive: photo.takenAt }, limit: GRID_THUMBNAILS_TO_SHOW_MAX + 1, }), ]); diff --git a/src/cache/index.ts b/src/cache/index.ts index 7673c577..fea2bf78 100644 --- a/src/cache/index.ts +++ b/src/cache/index.ts @@ -51,9 +51,11 @@ const getPhotosCacheKeyForOption = ( case 'offset': case 'tag': case 'simulation': + case 'beforePriorityOrder': + case 'afterPriorityOrderInclusive': case 'includeHidden': { const value = options[option]; - return value ? `${option}-${value}` : null; + return value !== undefined ? `${option}-${value}` : null; } // Date keys case 'takenBefore': diff --git a/src/services/vercel-postgres.ts b/src/services/vercel-postgres.ts index 7ab19c6f..d912f270 100644 --- a/src/services/vercel-postgres.ts +++ b/src/services/vercel-postgres.ts @@ -271,6 +271,8 @@ export type GetPhotosOptions = { simulation?: FilmSimulation takenBefore?: Date takenAfterInclusive?: Date + beforePriorityOrder?: number + afterPriorityOrderInclusive?: number includeHidden?: boolean } @@ -312,6 +314,8 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => { simulation, takenBefore, takenAfterInclusive, + beforePriorityOrder, + afterPriorityOrderInclusive, includeHidden, } = options; @@ -346,6 +350,14 @@ export const getPhotos = async (options: GetPhotosOptions = {}) => { wheres.push(`film_simulation=$${valueNumber++}`); values.push(simulation); } + if (beforePriorityOrder !== undefined) { + wheres.push(`id < $${valueNumber++}`); + values.push(beforePriorityOrder); + } + if (afterPriorityOrderInclusive !== undefined) { + wheres.push(`id >= $${valueNumber++}`); + values.push(afterPriorityOrderInclusive); + } if (wheres.length > 0) { sql += ` WHERE ${wheres.join(' AND ')}`; }