mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): move filters to getByDayOfYear query (#14628)
move filters to getByDayOfYear query
This commit is contained in:
parent
25ca3b1124
commit
9eff1c4b34
5 changed files with 55 additions and 38 deletions
|
|
@ -43,28 +43,13 @@ export class AssetService extends BaseService {
|
|||
});
|
||||
const userIds = [auth.user.id, ...partnerIds];
|
||||
|
||||
const assets = await this.assetRepository.getByDayOfYear(userIds, dto);
|
||||
const assetsWithThumbnails = assets.filter(({ files }) => !!getAssetFiles(files).thumbnailFile);
|
||||
const groups: Record<number, AssetEntity[]> = {};
|
||||
const currentYear = new Date().getFullYear();
|
||||
for (const asset of assetsWithThumbnails) {
|
||||
const yearsAgo = currentYear - asset.localDateTime.getFullYear();
|
||||
if (!groups[yearsAgo]) {
|
||||
groups[yearsAgo] = [];
|
||||
}
|
||||
groups[yearsAgo].push(asset);
|
||||
}
|
||||
|
||||
return Object.keys(groups)
|
||||
.map(Number)
|
||||
.sort((a, b) => a - b)
|
||||
.filter((yearsAgo) => yearsAgo > 0)
|
||||
.map((yearsAgo) => ({
|
||||
yearsAgo,
|
||||
// TODO move this to clients
|
||||
title: `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`,
|
||||
assets: groups[yearsAgo].map((asset) => mapAsset(asset, { auth })),
|
||||
}));
|
||||
const groups = await this.assetRepository.getByDayOfYear(userIds, dto);
|
||||
return groups.map(({ yearsAgo, assets }) => ({
|
||||
yearsAgo,
|
||||
// TODO move this to clients
|
||||
title: `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`,
|
||||
assets: assets.map((asset) => mapAsset(asset, { auth })),
|
||||
}));
|
||||
}
|
||||
|
||||
async getStatistics(auth: AuthDto, dto: AssetStatsDto) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue