Fix priority-ordered photo detail thumbnails

This commit is contained in:
Sam Becker 2023-12-18 08:42:59 -06:00
parent 32c6260a3b
commit 890b6c4f34
3 changed files with 25 additions and 3 deletions

View File

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

4
src/cache/index.ts vendored
View File

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

View File

@ -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 ')}`;
}