diff --git a/src/modules/albums/catalog.test.ts b/src/modules/albums/catalog.test.ts index ff2711b..503eb7f 100644 --- a/src/modules/albums/catalog.test.ts +++ b/src/modules/albums/catalog.test.ts @@ -112,6 +112,20 @@ test("moves the queried granted album to the active gallery context without losi ]); }); +test("global search keeps hits when a granted album is no longer visible in Immich", async () => { + const { catalog, immich } = createCatalog({ grantedAlbumIds: ["allowed", "missing"] }); + immich.searchPhotos.mockImplementation(async ({ albumIds: [id] }) => { + if (id === "missing") throw new Error("Album no longer accessible"); + return { + items: [{ id: `photo-${id}`, albums: [] }], + total: 1, nextPage: null, previousPage: null, + }; + }); + + const result = await catalog.searchVisiblePhotos("editorial-1", { description: "hsv" }); + expect(result.items.map(({ id }) => id)).toEqual(["photo-allowed"]); +}); + test("does not call Immich when an editorial has no current album grants", async () => { const { catalog, immich } = createCatalog({ grantedAlbumIds: [] }); diff --git a/src/modules/albums/catalog.ts b/src/modules/albums/catalog.ts index 00a40ee..6d78434 100644 --- a/src/modules/albums/catalog.ts +++ b/src/modules/albums/catalog.ts @@ -91,8 +91,10 @@ export function createAlbumCatalog({ grants, immich, consumeRateLimit: consume } // grant count and narrowed by the description filter, so per-album results // are small. If a huge-grant editorial makes this slow, cap the fan-out // and accept partial coverage. + const visibleIds = new Set((await loadAlbums(immich)).map(({ id }) => id)); const pages = await Promise.all( - grantedAlbumIds.map((albumId) => searchAlbum(immich, [albumId], description, page, size)), + grantedAlbumIds.filter((id) => visibleIds.has(id)) + .map((albumId) => searchAlbum(immich, [albumId], description, page, size)), ); return mergeSearchPages(pages); },