From cfd85a1fe84c3bad73dc025c729110a6b138dadf Mon Sep 17 00:00:00 2001 From: Claudio Date: Mon, 18 May 2026 00:06:01 +0200 Subject: [PATCH] fix(sidebar): root badge shows the library total, not zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Earlier we (a) wildcarded the per-folder count fan-out in the sidecar so internal tree nodes (year folders, etc.) recurse, and (b) flipped the timeline root view to mean "the whole library" instead of "photos with no path component". The remaining piece — the badge on the root row — still computed `total - Σ(folderCounts)`, which used to give the count of root-direct photos. With recursive folder counts that subtraction double-counts every nested photo (year + month + …) and clamps the badge to 0. Use PhotoPrism's authoritative `count.all` directly. That now matches what the timeline shows under `/` (everything indexed) without an extra round-trip. --- .../lib/components/layout/LeftSidebar.svelte | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/web/src/lib/components/layout/LeftSidebar.svelte b/web/src/lib/components/layout/LeftSidebar.svelte index 6596bec..4d1c1f8 100644 --- a/web/src/lib/components/layout/LeftSidebar.svelte +++ b/web/src/lib/components/layout/LeftSidebar.svelte @@ -158,15 +158,15 @@ })); const folderCounts = $derived(folderCountsQuery.data ?? {}); - // Root count = total photos minus the sum of every subfolder count. - // `config.count.all` is PhotoPrism's authoritative library total - // (kept in sync server-side); subtracting non-root photos gives an - // exact root-only count without a separate API trip. - const rootCount = $derived.by(() => { - const total = configQuery.data?.count?.all ?? 0; - const sub = Object.values(folderCounts).reduce((a, b) => a + b, 0); - return Math.max(0, total - sub); - }); + // Root entry shows the whole library — see applyFolderScope() on / + // timeline. PhotoPrism's `count.all` from /api/v1/config is the + // authoritative library total (kept in sync server-side), so use it + // directly. Earlier this subtracted Σ(folderCounts) from total, which + // worked when folderCounts were direct-child only; now that the + // sidecar fan-out recurses (see handlers_folders.go), every photo + // gets summed once per ancestor — the subtraction would double-count + // and drive rootCount to 0. + const rootCount = $derived(configQuery.data?.count?.all ?? 0); const createMut = createMutation(() => ({ mutationFn: (title: string) => createHeap(title),