From 32945a01b4ccc15b478e98e136b514f724cafd13 Mon Sep 17 00:00:00 2001 From: timonrieger Date: Fri, 29 May 2026 18:52:48 +0200 Subject: [PATCH] cleanup --- server/src/dtos/search.dto.ts | 4 ++-- server/src/utils/database.ts | 24 +++--------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/server/src/dtos/search.dto.ts b/server/src/dtos/search.dto.ts index 36b36de27b..1504a6e6ea 100644 --- a/server/src/dtos/search.dto.ts +++ b/server/src/dtos/search.dto.ts @@ -279,7 +279,7 @@ const StringSimilarityFilterSchema = z }) .meta({ id: 'StringSimilarityFilter' }); -const SearchOrderSchema = z +export const SearchOrderSchema = z .strictObject({ field: SearchOrderFieldSchema.default(SearchOrderField.FileCreatedAt), direction: AssetOrderSchema.default(AssetOrder.Desc), @@ -323,7 +323,7 @@ const SearchFilterBranchSchema = z }) .meta({ id: 'SearchFilterBranch' }); -const SearchFilterSchema = SearchFilterBranchSchema.extend({ +export const SearchFilterSchema = SearchFilterBranchSchema.extend({ or: z.array(SearchFilterBranchSchema).min(1).optional(), }).meta({ id: 'SearchFilter' }); diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index 5789c8c3a4..4222f5a96e 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -558,8 +558,8 @@ const FIELD_BACKING: Record, Backing> = { }; function branchNeedsExifJoin(branch: SearchFilterBranch): boolean { - for (const key of Object.keys(FIELD_BACKING) as (keyof typeof FIELD_BACKING)[]) { - if (FIELD_BACKING[key] === 'asset_exif' && branch[key] !== undefined) { + for (const key of Object.keys(branch) as (keyof typeof FIELD_BACKING)[]) { + if (FIELD_BACKING[key] === 'asset_exif') { return true; } } @@ -598,8 +598,6 @@ function exifJoinRequired(filter: SearchFilter, orderField: SearchOrderField): b */ type AssetEB = ExpressionBuilder; -// ---- EXISTS expression helpers (returned as Expression) ---- - function existsAlbumLink(eb: AssetEB, want: boolean): Expression { const e = eb.exists((eb2) => eb2.selectFrom('album_asset').whereRef('album_asset.assetId', '=', 'asset.id')); return want ? e : eb.not(e); @@ -665,8 +663,6 @@ function existsEncodedVideoPath(eb: AssetEB, f: StringFilter): Expression { @@ -747,15 +743,13 @@ function pushIdsFilter(preds: Expression[], eb: AssetEB, kind: IdsKind, preds.push(idsAnyExists(eb, kind, f.any)); } if (f.all) { - preds.push(idsAllExists(eb, kind, f.all)); + preds.push(f.all.length === 1 ? idsAnyExists(eb, kind, f.all) : idsAllExists(eb, kind, f.all)); } if (f.none) { preds.push(eb.not(idsAnyExists(eb, kind, f.none))); } } -// ---- Per-filter-family pushers ---- - function pushIdEqNe( preds: Expression[], eb: AssetEB, @@ -975,15 +969,12 @@ function pushChecksum(preds: Expression[], eb: AssetEB, f: StringFilter function buildBranchPredicates(eb: AssetEB, b: SearchFilterBranch): Expression[] { const p: Expression[] = []; - // id / libraryId pushIdEqNe(p, eb, 'asset.id', b.id); pushIdEqNe(p, eb, 'asset.libraryId', b.libraryId); - // enums pushEnum(p, eb, 'asset.type', b.type); pushEnum(p, eb, 'asset.visibility', b.visibility); - // bools on asset if (b.isFavorite) { p.push(eb('asset.isFavorite', '=', b.isFavorite.eq)); } @@ -997,7 +988,6 @@ function buildBranchPredicates(eb: AssetEB, b: SearchFilterBranch): Expression