Skip to content

High performance self-hosted photo and video management solution.

fix(server): Fix for sorting faces during merging (#15571)

Lukas065d885ca0bb
diff --git a/server/src/repositories/person.repository.ts b/server/src/repositories/person.repository.ts
index fdcecd9d0a..45183f39d6 100644
--- a/server/src/repositories/person.repository.ts
+++ b/server/src/repositories/person.repository.ts
@@ -133,10 +133,6 @@ export class PersonRepository implements IPersonRepository {
)
.where('person.ownerId', '=', userId)
.orderBy('person.isHidden', 'asc')
- .orderBy(sql`NULLIF(person.name, '') is null`, 'asc')
- .orderBy((eb) => eb.fn.count('asset_faces.assetId'), 'desc')
- .orderBy(sql`NULLIF(person.name, '')`, sql`asc nulls last`)
- .orderBy('person.createdAt')
.having((eb) =>
eb.or([
eb('person.name', '!=', ''),
@@ -161,6 +157,13 @@ export class PersonRepository implements IPersonRepository {
),
),
)
+ .$if(!options?.closestFaceAssetId, (qb) =>
+ qb
+ .orderBy(sql`NULLIF(person.name, '') is null`, 'asc')
+ .orderBy((eb) => eb.fn.count('asset_faces.assetId'), 'desc')
+ .orderBy(sql`NULLIF(person.name, '')`, sql`asc nulls last`)
+ .orderBy('person.createdAt'),
+ )
.$if(!options?.withHidden, (qb) => qb.where('person.isHidden', '=', false))
.offset(pagination.skip ?? 0)
.limit(pagination.take + 1)