fix(server): Correctly set album start and end dates (#4698)
* fix(server): Correctly set album start and end dates Currently, the query that retrieves album assets uses `ORDER BY assets.fileCreatedAt DESC`, which makes the existing logic return the start/end dates reversed (with `startDate` being taken from the first asset in the array). Instead of using the index-based approach, this change iterates through assets to get the min/max `fileCreatedAt`. This will avoid any future issues, if the query ordering changes, or becomes customizable (e.g. in case the user prefers to visualize older assets first). * fix: Maintain constant cost and only swap variables if needed
This commit is contained in:
committed by
GitHub
parent
87a0ba3db3
commit
b6f18cbe81
@@ -36,6 +36,15 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean): AlbumRespons
|
||||
const hasSharedLink = entity.sharedLinks?.length > 0;
|
||||
const hasSharedUser = sharedUsers.length > 0;
|
||||
|
||||
let startDate = assets.at(0)?.fileCreatedAt || undefined;
|
||||
let endDate = assets.at(-1)?.fileCreatedAt || undefined;
|
||||
// Swap dates if start date is greater than end date.
|
||||
if (startDate && endDate && startDate > endDate) {
|
||||
const temp = startDate;
|
||||
startDate = endDate;
|
||||
endDate = temp;
|
||||
}
|
||||
|
||||
return {
|
||||
albumName: entity.albumName,
|
||||
description: entity.description,
|
||||
@@ -48,8 +57,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean): AlbumRespons
|
||||
sharedUsers,
|
||||
shared: hasSharedUser || hasSharedLink,
|
||||
hasSharedLink,
|
||||
startDate: assets.at(0)?.fileCreatedAt || undefined,
|
||||
endDate: assets.at(-1)?.fileCreatedAt || undefined,
|
||||
startDate,
|
||||
endDate,
|
||||
assets: (withAssets ? assets : []).map((asset) => mapAsset(asset)),
|
||||
assetCount: entity.assets?.length || 0,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user