From 44eeb1e088dd8e0a2f7b607316e86d3c73b30d29 Mon Sep 17 00:00:00 2001 From: Joe Babbitt Date: Tue, 3 Mar 2026 06:41:29 -0500 Subject: [PATCH] fix: implement existing withStacked on searchAssetBuilder (#26607) Co-authored-by: Joe --- server/src/utils/database.ts | 1 + .../specs/services/search.service.spec.ts | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index 4dd0c9b302..4a57cd1a98 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -404,6 +404,7 @@ export function searchAssetBuilder(kysely: Kysely, options: AssetSearchBuild .$if(!!options.isNotInAlbum && (!options.albumIds || options.albumIds.length === 0), (qb) => qb.where((eb) => eb.not(eb.exists((eb) => eb.selectFrom('album_asset').whereRef('assetId', '=', 'asset.id')))), ) + .$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.withDeleted, (qb) => qb.where('asset.deletedAt', 'is', null)); diff --git a/server/test/medium/specs/services/search.service.spec.ts b/server/test/medium/specs/services/search.service.spec.ts index f58ffb6a25..c20b64ca7c 100644 --- a/server/test/medium/specs/services/search.service.spec.ts +++ b/server/test/medium/specs/services/search.service.spec.ts @@ -88,4 +88,24 @@ describe(SearchService.name, () => { expect(result).toEqual({ total: 0 }); }); }); + + describe('withStacked option', () => { + it('should exclude stacked assets when withStacked is false', async () => { + const { sut, ctx } = setup(); + const { user } = await ctx.newUser(); + + const { asset: primaryAsset } = await ctx.newAsset({ ownerId: user.id }); + const { asset: stackedAsset } = await ctx.newAsset({ ownerId: user.id }); + const { asset: unstackedAsset } = await ctx.newAsset({ ownerId: user.id }); + + await ctx.newStack({ ownerId: user.id }, [primaryAsset.id, stackedAsset.id]); + + const auth = factory.auth({ user: { id: user.id } }); + + const response = await sut.searchMetadata(auth, { withStacked: false }); + + expect(response.assets.items.length).toBe(1); + expect(response.assets.items[0].id).toBe(unstackedAsset.id); + }); + }); });