Skip to content

Commit

Permalink
fix(server): duplicate faces, face insert query failing (immich-app#1…
Browse files Browse the repository at this point in the history
…3294)

fix duplicate faces, query failing
  • Loading branch information
mertalev authored and Yosi Taguri committed Oct 16, 2024
1 parent cc31c59 commit 07271f6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion server/src/repositories/person.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export class PersonRepository implements IPersonRepository {
faceIdsToRemove: string[],
embeddingsToAdd?: FaceSearchEntity[],
): Promise<void> {
const query = this.faceSearchRepository.createQueryBuilder().select('1');
const query = this.faceSearchRepository.createQueryBuilder().select('1').fromDummy();
if (facesToAdd.length > 0) {
const insertCte = this.assetFaceRepository.createQueryBuilder().insert().values(facesToAdd);
query.addCommonTableExpression(insertCte, 'added');
Expand All @@ -296,6 +296,7 @@ export class PersonRepository implements IPersonRepository {
if (embeddingsToAdd?.length) {
const embeddingCte = this.faceSearchRepository.createQueryBuilder().insert().values(embeddingsToAdd).orIgnore();
query.addCommonTableExpression(embeddingCte, 'embeddings');
query.getQuery(); // typeorm mixes up parameters without this
}

await query.execute();
Expand Down
2 changes: 1 addition & 1 deletion server/src/services/person.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class PersonService extends BaseService {

if (match && !mlFaceIds.delete(match.id)) {
embeddings.push({ faceId: match.id, embedding });
} else {
} else if (!match) {
const faceId = this.cryptoRepository.randomUUID();
facesToAdd.push({
id: faceId,
Expand Down

0 comments on commit 07271f6

Please sign in to comment.