From e671b30aaf3d8aeaaf898767b5ab7f06df258b2a Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Sun, 5 Nov 2023 11:07:29 -0500 Subject: [PATCH] fix(server): duplicate faces bug (#4844) --- .../src/domain/person/person.service.spec.ts | 19 ++++++++++++++++++- server/src/domain/person/person.service.ts | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/domain/person/person.service.spec.ts b/server/src/domain/person/person.service.spec.ts index 9d966460e1..59b33f4dc6 100644 --- a/server/src/domain/person/person.service.spec.ts +++ b/server/src/domain/person/person.service.spec.ts @@ -1,4 +1,4 @@ -import { Colorspace, SystemConfigKey } from '@app/infra/entities'; +import { AssetFaceEntity, Colorspace, SystemConfigKey } from '@app/infra/entities'; import { BadRequestException, NotFoundException } from '@nestjs/common'; import { IAccessRepositoryMock, @@ -449,6 +449,23 @@ describe(PersonService.name, () => { expect(machineLearningMock.detectFaces).not.toHaveBeenCalled(); }); + it('should skip it the asset has already been processed', async () => { + assetMock.getByIds.mockResolvedValue([ + { + ...assetStub.noResizePath, + faces: [ + { + id: 'asset-face-1', + assetId: assetStub.noResizePath.id, + personId: faceStub.face1.personId, + } as AssetFaceEntity, + ], + }, + ]); + await sut.handleRecognizeFaces({ id: assetStub.noResizePath.id }); + expect(machineLearningMock.detectFaces).not.toHaveBeenCalled(); + }); + it('should handle no results', async () => { machineLearningMock.detectFaces.mockResolvedValue([]); assetMock.getByIds.mockResolvedValue([assetStub.image]); diff --git a/server/src/domain/person/person.service.ts b/server/src/domain/person/person.service.ts index dcf5dbb78d..b6e7bf0b9f 100644 --- a/server/src/domain/person/person.service.ts +++ b/server/src/domain/person/person.service.ts @@ -217,7 +217,7 @@ export class PersonService { } const [asset] = await this.assetRepository.getByIds([id]); - if (!asset || !asset.resizePath) { + if (!asset || !asset.resizePath || asset.faces?.length > 0) { return false; }