fix(server): duplicate faces bug (#4844)

This commit is contained in:
Jason Rasmussen 2023-11-05 11:07:29 -05:00 committed by GitHub
parent cf1dfdc776
commit e671b30aaf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

View file

@ -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]);

View file

@ -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;
}