Fix recent upload time calculation

This commit is contained in:
Sam Becker 2026-01-30 21:54:44 -06:00
parent 6b4c4970a3
commit 5f20bbd0f4
2 changed files with 15 additions and 4 deletions

View File

@ -42,10 +42,10 @@ export const NULL_CATEGORY_DATA: CategoryData = {
export const getDataForCategories = () => Promise.all([
SHOW_RECENTS
? getPhotosMetaCached({ recent: true })
.then(({ count, dateRange }) => count && dateRange
.then(({ count, dateRangeCreatedAt }) => count && dateRangeCreatedAt
? [{
count,
lastModified: new Date(dateRange?.end ?? ''),
lastModified: new Date(dateRangeCreatedAt?.end ?? ''),
}] : undefined)
.catch(() => [])
: undefined,

View File

@ -497,8 +497,12 @@ export const getPhotosNearId = async (
export const getPhotosMeta = (options: PhotoQueryOptions = {}) =>
safelyQuery(async () => {
// eslint-disable-next-line max-len
let sql = 'SELECT COUNT(*), MIN(p.taken_at_naive) as start, MAX(p.taken_at_naive) as end FROM photos p';
let sql = `
SELECT COUNT(*),
MIN(p.taken_at_naive) as start, MAX(p.taken_at_naive) as end,
MIN(p.created_at) as start_created_at, MAX(p.created_at) as end_created_at
FROM photos p
`;
const joins = getJoinsFromOptions(options);
if (joins) { sql += ` ${joins}`; }
const { wheres, wheresValues } = getWheresFromOptions(options);
@ -512,6 +516,13 @@ export const getPhotosMeta = (options: PhotoQueryOptions = {}) =>
end: rows[0].end as string,
} as PhotoDateRangePostgres }
: undefined,
// Used to calculate upload time for 'recents'
...rows[0]?.start_created_at && rows[0]?.end_created_at
? { dateRangeCreatedAt: {
start: rows[0].start_created_at as string,
end: rows[0].end_created_at as string,
} as PhotoDateRangePostgres }
: undefined,
}));
}, 'getPhotosMeta');