mirror of
https://github.com/immich-app/immich.git
synced 2025-12-26 01:11:47 +03:00
fix: memories off by one (#16434)
This commit is contained in:
@@ -64,18 +64,18 @@ describe(AssetService.name, () => {
|
||||
mocks.partner.getAll.mockResolvedValue([]);
|
||||
mocks.asset.getByDayOfYear.mockResolvedValue([
|
||||
{
|
||||
yearsAgo: 1,
|
||||
year: 2023,
|
||||
assets: [image1, image2],
|
||||
},
|
||||
{
|
||||
yearsAgo: 9,
|
||||
year: 2015,
|
||||
assets: [image3],
|
||||
},
|
||||
{
|
||||
yearsAgo: 15,
|
||||
year: 2009,
|
||||
assets: [image4],
|
||||
},
|
||||
]);
|
||||
] as any);
|
||||
|
||||
await expect(sut.getMemoryLane(authStub.admin, { day: 15, month: 1 })).resolves.toEqual([
|
||||
{ yearsAgo: 1, title: '1 year ago', assets: [mapAsset(image1), mapAsset(image2)] },
|
||||
|
||||
@@ -38,12 +38,15 @@ export class AssetService extends BaseService {
|
||||
const userIds = [auth.user.id, ...partnerIds];
|
||||
|
||||
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 })),
|
||||
}));
|
||||
return groups.map(({ year, assets }) => {
|
||||
const yearsAgo = DateTime.utc().year - year;
|
||||
return {
|
||||
yearsAgo,
|
||||
// TODO move this to clients
|
||||
title: `${yearsAgo} year${yearsAgo > 1 ? 's' : ''} ago`,
|
||||
assets: assets.map((asset) => mapAsset(asset as AssetEntity, { auth })),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async getStatistics(auth: AuthDto, dto: AssetStatsDto) {
|
||||
|
||||
@@ -45,18 +45,18 @@ export class MemoryService extends BaseService {
|
||||
for (const [userId, userIds] of Object.entries(userMap)) {
|
||||
const memories = await this.assetRepository.getByDayOfYear(userIds, target);
|
||||
|
||||
for (const memory of memories) {
|
||||
const data: OnThisDayData = { year: target.year - memory.yearsAgo };
|
||||
for (const { year, assets } of memories) {
|
||||
const data: OnThisDayData = { year };
|
||||
await this.memoryRepository.create(
|
||||
{
|
||||
ownerId: userId,
|
||||
type: MemoryType.ON_THIS_DAY,
|
||||
data,
|
||||
memoryAt: target.minus({ years: memory.yearsAgo }).toISO(),
|
||||
memoryAt: target.set({ year }).toISO(),
|
||||
showAt,
|
||||
hideAt,
|
||||
},
|
||||
new Set(memory.assets.map(({ id }) => id)),
|
||||
new Set(assets.map(({ id }) => id)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user