diff --git a/src/category/data.ts b/src/category/data.ts index d885f0fb..84a78dab 100644 --- a/src/category/data.ts +++ b/src/category/data.ts @@ -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, diff --git a/src/photo/query.ts b/src/photo/query.ts index 85854fcd..2082153f 100644 --- a/src/photo/query.ts +++ b/src/photo/query.ts @@ -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');