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 ?? {});
|
||||
|
||||
// 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),
|
||||
|
||||
Reference in New Issue
Block a user