fix(desktop): read hover-card diff stats once instead of watching the worktree
HEAD: patiently:pr/hover-diff-stats-once → BASE: superset-sh:main
What & why
Refs #7877 (cause 2).
The sidebar hover card calls useDiffStats(hoveredId), which subscribes to git:changed. That makes the host's GitWatcher attach a recursive watch of the hovered worktree (about 23k inotify watches on a monorepo) just to show two numbers. Hovering down the sidebar attaches one watch per workspace hovered.
useDiffStats takes a live option, defaulting to true. The hover card reads with live: false: it fetches git status once, treats the result as fresh for 30 s, and never subscribes. The active workspace's stats stay live as before.
How I tested it
- New
useDiffStats.test.tsx: the default read subscribes togit:changed, and a one-shot read fetches the stats without subscribing. In CI on our fork, the one-shot test failed against the previoususeDiffStats.tsand passes with this change: https://github.com/patiently/superset/actions/runs/36232163346 ("Ignored-dir cap and hover-stats tests fail without the fix", then "Desktop test suite"). That run also passed lint and the desktop typecheck. - A/B on
main2370f60d4 with 6 scripted hover sweeps (6 workspaces × 1.5 s each, real pointer, every card confirmed by screenshot; method in #7877). With the watch count as the signal, hovering alone added 6–26k watches per sweep on control, and once 287k. With this change it added 0. - The card's content is unchanged; only how the stats are fetched differs.
Checklist
- PR title follows conventional commits (
type(scope): subject) -
bun run lintandbun run typecheckpass (fork CI run above) - "Allow edits from maintainers" is checked on fork PRs. Not available: this PR comes from an organization-owned fork, and GitHub doesn't offer that option for those. Happy to push any changes you'd like.
Summary by cubic
Fixes the sidebar hover card reading diff stats once instead of subscribing to git:changed, which made the host attach a recursive worktree watch (~23k inotify watches on a monorepo) per hovered workspace, kept alive for another minute by the watcher. The card now fetches git status once, treats the result as fresh for 30 s, and never subscribes. The active workspace's stats stay live.
Testing
- Adds
useDiffStatstests covering the default live read and the new one-shot read; the one-shot test fails against the previous implementation.
Summary by CodeRabbit
- New Features
- Diff statistics now support live and non-live update modes. Live updates remain enabled by default; non-live results become eligible for refresh after 30 seconds.
- Behavior Changes
- Diff statistics shown in the dashboard hover card no longer update immediately when Git changes occur. The card uses non-live results, which are fetched without subscribing to live changes.