perf(desktop): only query diff stats for the active sidebar workspace item
Merged
KI
3mo ago+13+13+01234567890123456789-3-3-0123456789
Summary
Every DashboardSidebarWorkspaceItem called useDiffStats(id), firing a background git.getStatus request per sidebar workspace — even though the expanded row only renders the +/− line-count badge for the active item. On a sidebar with N workspaces, N−1 of those git status reads were pure waste.
useDiffStatsnow takes an optional{ enabled }option (defaults totrue; hover-card overlay and other callers unaffected) gating thegit.getStatusquery.- The
git:changedsubscription intentionally stays on while disabled: it's a cheap listener on the shared per-host event bus, and its invalidation marks the cached stats stale so counts refetch when the item becomes active again (withstaleTime: Infinity, gating it would freeze counts at their last-active values). DashboardSidebarWorkspaceItempasses{ enabled: isActive }.
The v1 WorkspaceSidebar already gates its fetch on hover, so no changes there.
Test plan
bun run lintclean,tsc --noEmitpasses inapps/desktop- Active workspace row still shows +/− diff stats and updates on git changes
- Switching to a workspace whose files changed while it was inactive refetches (invalidation marks the disabled query stale)
Summary by cubic
Fetch diff stats only for the active sidebar workspace to eliminate redundant git.getStatus calls and reduce background work. useDiffStats now accepts { enabled }, used by DashboardSidebarWorkspaceItem, while the git:changed subscription remains to invalidate stale data so counts refresh when the item becomes active again.