From ae4900d71c7110152e2eb6953deb409ebfa7e603 Mon Sep 17 00:00:00 2001 From: mertalev <101130780+mertalev@users.noreply.github.com> Date: Sun, 5 Nov 2023 19:44:31 -0500 Subject: [PATCH] set relations for `getByIds` --- server/src/domain/person/person.service.ts | 8 +++++++- server/src/domain/repositories/asset.repository.ts | 3 ++- server/src/infra/repositories/asset.repository.ts | 13 ++++++++----- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/server/src/domain/person/person.service.ts b/server/src/domain/person/person.service.ts index b6e7bf0b9..0d8f9b6b8 100644 --- a/server/src/domain/person/person.service.ts +++ b/server/src/domain/person/person.service.ts @@ -216,7 +216,13 @@ export class PersonService { return true; } - const [asset] = await this.assetRepository.getByIds([id]); + const relations = { + exifInfo: true, + faces: { + person: true, + }, + }; + const [asset] = await this.assetRepository.getByIds([id], relations); if (!asset || !asset.resizePath || asset.faces?.length > 0) { return false; } diff --git a/server/src/domain/repositories/asset.repository.ts b/server/src/domain/repositories/asset.repository.ts index bdbdd78f2..4b11cb55a 100644 --- a/server/src/domain/repositories/asset.repository.ts +++ b/server/src/domain/repositories/asset.repository.ts @@ -1,4 +1,5 @@ import { AssetEntity, AssetType, ExifEntity } from '@app/infra/entities'; +import { FindOptionsRelations } from 'typeorm'; import { Paginated, PaginationOptions } from '../domain.util'; export type AssetStats = Record; @@ -99,7 +100,7 @@ export const IAssetRepository = 'IAssetRepository'; export interface IAssetRepository { create(asset: AssetCreate): Promise; getByDate(ownerId: string, date: Date): Promise; - getByIds(ids: string[]): Promise; + getByIds(ids: string[], relations?: FindOptionsRelations): Promise; getByDayOfYear(ownerId: string, monthDay: MonthDay): Promise; getByChecksum(userId: string, checksum: Buffer): Promise; getByAlbumId(pagination: PaginationOptions, albumId: string): Paginated; diff --git a/server/src/infra/repositories/asset.repository.ts b/server/src/infra/repositories/asset.repository.ts index c237a3604..199842ed4 100644 --- a/server/src/infra/repositories/asset.repository.ts +++ b/server/src/infra/repositories/asset.repository.ts @@ -104,10 +104,9 @@ export class AssetRepository implements IAssetRepository { .getMany(); } - getByIds(ids: string[]): Promise { - return this.repository.find({ - where: { id: In(ids) }, - relations: { + getByIds(ids: string[], relations?: FindOptionsRelations): Promise { + if (!relations) { + relations = { exifInfo: true, smartInfo: true, tags: true, @@ -115,7 +114,11 @@ export class AssetRepository implements IAssetRepository { person: true, }, stack: true, - }, + }; + } + return this.repository.find({ + where: { id: In(ids) }, + relations, withDeleted: true, }); }