fix(sidebar): root badge shows the library total, not zero
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.
This commit is contained in:
@@ -158,15 +158,15 @@
|
|||||||
}));
|
}));
|
||||||
const folderCounts = $derived(folderCountsQuery.data ?? {});
|
const folderCounts = $derived(folderCountsQuery.data ?? {});
|
||||||
|
|
||||||
// Root count = total photos minus the sum of every subfolder count.
|
// Root entry shows the whole library — see applyFolderScope() on /
|
||||||
// `config.count.all` is PhotoPrism's authoritative library total
|
// timeline. PhotoPrism's `count.all` from /api/v1/config is the
|
||||||
// (kept in sync server-side); subtracting non-root photos gives an
|
// authoritative library total (kept in sync server-side), so use it
|
||||||
// exact root-only count without a separate API trip.
|
// directly. Earlier this subtracted Σ(folderCounts) from total, which
|
||||||
const rootCount = $derived.by(() => {
|
// worked when folderCounts were direct-child only; now that the
|
||||||
const total = configQuery.data?.count?.all ?? 0;
|
// sidecar fan-out recurses (see handlers_folders.go), every photo
|
||||||
const sub = Object.values(folderCounts).reduce((a, b) => a + b, 0);
|
// gets summed once per ancestor — the subtraction would double-count
|
||||||
return Math.max(0, total - sub);
|
// and drive rootCount to 0.
|
||||||
});
|
const rootCount = $derived(configQuery.data?.count?.all ?? 0);
|
||||||
|
|
||||||
const createMut = createMutation(() => ({
|
const createMut = createMutation(() => ({
|
||||||
mutationFn: (title: string) => createHeap(title),
|
mutationFn: (title: string) => createHeap(title),
|
||||||
|
|||||||
Reference in New Issue
Block a user