Repository navigation
perf(renderer): purge sparse-preset maps when a repo is removed - #7564
Conversation
The four per-repo maps (sparsePresetsByRepo, sparsePresetsLoadingByRepo, sparsePresetsLoadStatusByRepo, sparsePresetsErrorByRepo) are populated lazily by fetchSparsePresets but were never pruned on repo removal, so orphaned entries accumulated for the renderer's whole session (repoIds are random UUIDs, never reused, so re-adding a repo can't reclaim old keys). Add omitSparsePresetsForRepos and call it from both repo-removal reducers (removeProject + deleteProjectHostSetup), scoped to repo ids with no surviving entry so a duplicate id on another host stays. Co-authored-by: Orca <[email protected]>
📝 WalkthroughWalkthroughThis change adds a helper function, Changes
Related PRs: None identified. Suggested labels: bug, renderer, store Suggested reviewers: None identified. Poem 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/renderer/src/store/slices/repos.ts (1)
2255-2262: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winWiring is correct; only path lacking direct test coverage.
The
removedRepoIdsderivation here mirrorsremoveProject's (correctly preserves duplicate repo IDs on other hosts), but the new regression test only exercisesremoveProject. If this branch'srepos/removedRepoIdscomputation regresses independently, nothing would catch it.src/renderer/src/store/slices/sparse-presets-repo-removal-purge-leak.test.ts (1)
51-70: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winSolid regression test; consider also covering
deleteProjectHostSetup.This verifies the
removeProjectpurge path well. SincedeleteProjectHostSetup(repos.ts lines 2255-2262) independently computesremovedRepoIdsand calls the same helper, a similar test there would guard against a silent regression in that path.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2f69115a-575e-43bb-a371-6878e4194594
📒 Files selected for processing (3)
src/renderer/src/store/slices/repos.tssrc/renderer/src/store/slices/sparse-presets-repo-removal-purge-leak.test.tssrc/renderer/src/store/slices/sparse-presets.ts
…lyai#7564) Co-authored-by: Orca <[email protected]>
Part of a full-codebase memory-leak audit — one never-purged per-entity structure per PR.
Description
The sparse-preset feature keeps four per-repo maps in the store —
sparsePresetsByRepo,sparsePresetsLoadingByRepo,sparsePresetsLoadStatusByRepo,sparsePresetsErrorByRepo— populated lazily byfetchSparsePresets(repoId). None of the repo-removal reducers pruned them, so an entry for every touched-then-removed repo lingered for the renderer's whole session.Fix: add
omitSparsePresetsForRepos(state, removedRepoIds)and call it from both repo-removal reducers (removeProjectanddeleteProjectHostSetup).Evidence
store/slices/sparse-presets.ts: the four maps are only ever written per repoId; the slice has no removal reducer.store/slices/repos.ts:removeProject(nextRepos = s.repos.filter(...)) anddeleteProjectHostSetupshrinks.reposbut left the sparse-preset maps untouched, unlike the ~30 worktree-scoped maps they already purge.Proof of fix
New test
sparse-presets-repo-removal-purge-leak.test.tsseeds all four maps for two repos, drives the realremoveProjectreducer, and asserts every map key is gone for the removed repo and intact for the surviving one.Typecheck (web) + oxlint clean.
ELI5
Each project could remember a few "sparse checkout presets." When you deleted a project, the app forgot the project but kept its preset notes forever. Now deleting a project also throws away its preset notes — and only that project's, leaving other projects' notes alone.
Trade-offs
survivingRepoIds), so removing a repo id on one host while a duplicate id remains on another host keeps the presets. Mirrors the existingrepoIdFullyRemovedlogic in the same reducer.Made with Orca 🐋