From 4289a9f23d48248f0779cd2efff91875cfe98b52 Mon Sep 17 00:00:00 2001 From: Yaros Date: Wed, 25 Mar 2026 11:18:29 +0100 Subject: [PATCH] fix(server): withPeople inconsistent --- server/src/utils/database.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index 03998d9462..eb55e9c8c0 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -171,6 +171,22 @@ export function hasPeople(qb: SelectQueryBuilder, personIds: ); } +export function excludeAssetsWithPeople(qb: SelectQueryBuilder) { + return qb.where((eb) => + eb.not( + eb.exists((eb) => + eb + .selectFrom('asset_face') + .select('asset_face.assetId') + .whereRef('asset_face.assetId', '=', 'asset.id') + .where('asset_face.deletedAt', 'is', null) + .where('asset_face.isVisible', 'is', true) + .where('asset_face.personId', 'is not', null), + ), + ), + ); +} + export function inAlbums(qb: SelectQueryBuilder, albumIds: string[]) { return qb.innerJoin( (eb) => @@ -306,6 +322,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('tag_asset').whereRef('assetId', '=', 'asset.id')))), ) .$if(!!options.personIds && options.personIds.length > 0, (qb) => hasPeople(qb, options.personIds!)) + .$if(options.withPeople === false && !options.personIds?.length, (qb) => excludeAssetsWithPeople(qb)) .$if(!!options.createdBefore, (qb) => qb.where('asset.createdAt', '<=', options.createdBefore!)) .$if(!!options.createdAfter, (qb) => qb.where('asset.createdAt', '>=', options.createdAfter!)) .$if(!!options.updatedBefore, (qb) => qb.where('asset.updatedAt', '<=', options.updatedBefore!)) @@ -407,7 +424,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild ) .$if(options.withStacked === false, (qb) => qb.where('asset.stackId', 'is', null)) .$if(!!options.withExif, withExifInner) - .$if(!!(options.withFaces || options.withPeople), (qb) => qb.select(withFacesAndPeople)) + .$if(!!options.withFaces || !!options.personIds, (qb) => qb.select(withFacesAndPeople)) .$if(!options.withDeleted, (qb) => qb.where('asset.deletedAt', 'is', null)); }