From 227c1e62165f880a6dfc47421ffc6ca32894ae21 Mon Sep 17 00:00:00 2001 From: timonrieger Date: Tue, 2 Jun 2026 16:59:05 +0200 Subject: [PATCH] clean comments --- server/src/dtos/search.dto.ts | 2 -- server/src/utils/database.ts | 29 ++--------------------------- 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/server/src/dtos/search.dto.ts b/server/src/dtos/search.dto.ts index 1504a6e6ea..b8c8464203 100644 --- a/server/src/dtos/search.dto.ts +++ b/server/src/dtos/search.dto.ts @@ -148,8 +148,6 @@ const SearchSuggestionRequestSchema = z }) .meta({ id: 'SearchSuggestionRequestDto' }); -// v3 SearchFilter DTOs — new shape introduced alongside the legacy flat DTOs above. - const atLeastOneKey = (schema: T) => { const keys = Object.keys(schema.shape); return schema.refine((value) => Object.values(value).some((v) => v !== undefined), { diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index f4ce2cd772..70c126e41e 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -509,19 +509,8 @@ export function searchAssetBuilderLegacy(kysely: Kysely, options: AssetSearc .$if(!options.withDeleted, (qb) => qb.where('asset.deletedAt', 'is', null)); } -/** - * Join strategy each `SearchFilterBranch` field needs against the database. - * - `asset`: column on the `asset` table; simple WHERE; no join. - * - `asset_exif`: column on `asset_exif`; inner join - * - `asset_file`: column on `asset_file`; SQL is field-dependent - * - `ocr_search`: specialised trigram-indexed search column - * - `membership`: not a column; junction-table membership; SQL is operator-dependent - */ type Backing = 'asset' | 'asset_exif' | 'asset_file' | 'ocr_search' | 'membership'; -/** - * Exhaustive `SearchFilterBranch` backing map - */ const FIELD_BACKING: Record, Backing> = { id: 'asset', libraryId: 'asset', @@ -566,9 +555,6 @@ function branchNeedsExifJoin(branch: SearchFilterBranch): boolean { return false; } -/** - * Exhaustive `SearchOrderField` backing map - */ const ORDER_BACKING = { [SearchOrderField.FileCreatedAt]: 'asset', [SearchOrderField.LocalDateTime]: 'asset', @@ -576,9 +562,6 @@ const ORDER_BACKING = { [SearchOrderField.Rating]: 'asset_exif', } satisfies Record; -/** - * `asset_exif` join is needed when either any filter or order field needs `asset_exif` - */ function exifJoinRequired(filter: SearchFilter, orderField: SearchOrderField): boolean { if (ORDER_BACKING[orderField] === 'asset_exif') { return true; @@ -589,13 +572,6 @@ function exifJoinRequired(filter: SearchFilter, orderField: SearchOrderField): b return filter.or?.some((branch) => branchNeedsExifJoin(branch)) ?? false; } -/** - * EB type used by `buildBranchPredicates`. The runtime invariant is that - * whenever a predicate references an `asset_exif` column, the `asset_exif` - * join has already been planted at the top of the builder chain (guaranteed - * by `exifJoinRequired`). `searchAssetBuilder` casts its `eb` into this type - * because TS can't see through the conditional `.$if(needsExifJoin, …)`. - */ type AssetExpressionBuilder = ExpressionBuilder; function existsAlbumLink(eb: AssetExpressionBuilder, present: boolean) { @@ -780,9 +756,7 @@ function pushEnum( if (!f) { return; } - // Values cast: column type unions across asset.type / asset.visibility resolve - // to `AssetType | AssetVisibility` and TS can't narrow to the caller's T. - // The caller side (the SearchFilter enum schemas) is what guarantees validity. + // `as never`: kysely's column-union type can't narrow to T; SearchFilter enum schemas validate at the boundary. if (f.eq !== undefined) { preds.push(eb(column, '=', f.eq as never)); } @@ -1086,6 +1060,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild return top.length > 0 ? eb.and(top) : eb.val(true); }) .$call((qb) => + // cast: `.$if(needsExifJoin, ...)` doesn't carry the join into the type; `exifJoinRequired` guarantees it at runtime. applySearchOrder(qb as SelectQueryBuilder, orderField, orderDirection), ); }