From b1b215f0836e575162b5183d63cdf4ce5e3c1140 Mon Sep 17 00:00:00 2001 From: shalong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Date: Mon, 14 Aug 2023 21:39:26 +0530 Subject: [PATCH] fix(server): sort un-named faces in query (#3662) --- server/src/domain/person/person.service.ts | 4 +--- server/src/infra/repositories/person.repository.ts | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/server/src/domain/person/person.service.ts b/server/src/domain/person/person.service.ts index 0758b5f2c9..0f66447f13 100644 --- a/server/src/domain/person/person.service.ts +++ b/server/src/domain/person/person.service.ts @@ -27,10 +27,8 @@ export class PersonService { async getAll(authUser: AuthUserDto, dto: PersonSearchDto): Promise { const people = await this.repository.getAll(authUser.id, { minimumFaceCount: 1 }); - const named = people.filter((person) => !!person.name); - const unnamed = people.filter((person) => !person.name); - const persons: PersonResponseDto[] = [...named, ...unnamed] + const persons: PersonResponseDto[] = people // with thumbnails .filter((person) => !!person.thumbnailPath) .map((person) => mapPerson(person)); diff --git a/server/src/infra/repositories/person.repository.ts b/server/src/infra/repositories/person.repository.ts index db4ccff06b..8595484365 100644 --- a/server/src/infra/repositories/person.repository.ts +++ b/server/src/infra/repositories/person.repository.ts @@ -56,6 +56,7 @@ export class PersonRepository implements IPersonRepository { .leftJoin('person.faces', 'face') .where('person.ownerId = :userId', { userId }) .orderBy('COUNT(face.assetId)', 'DESC') + .addOrderBy("NULLIF(person.name, '')", 'ASC', 'NULLS LAST') .having('COUNT(face.assetId) >= :faces', { faces: options?.minimumFaceCount || 1 }) .groupBy('person.id') .limit(500)