·6 min read
Removing a work folder in DailyBrief no longer triggers a full disk rescan
I removed a folder from DailyBrief's work-folder list, and the app went off to walk the disk again to find out what was no longer there. That is the wrong amount of work: a removal cannot reveal anything new, and the project registry already drops stale entries on its regular scan. The fix was five lines, but it depends on a set comparison that is easy to get subtly wrong.
- Project
- DailyBrief
- Date
- Oct 2026
- Stack
- Electron, Node.js, PowerShell
- Commit
- 720259c
Where work folders come from
DailyBrief finds your projects by walking a list of work roots. A few commits earlier, in 44a43b7, I made that list configurable: the Windows defaults (Desktop, Documents, a few more) plus any folder you add in Settings, on any drive, and the ability to switch the built-in ones off. roots.json stores the user's list and the disabled list. The helper effectiveRoots(userRoots, defaults, isDir, disabled) in src/roots.js turns those into what is actually walked: user folders first, de-duplicated case-insensitively, missing folders dropped, disabled defaults left out.
The walk is the expensive part. In the same commit I replaced the old stack-based walk in core/discover-dirs.ps1 with a shared walk.ps1 that never enters excluded or dependency folders, and I added a rule for nested roots:
# A root nested inside another root is already covered by the outer walk;
# walking it again would only count every change twice.
$walkRoots = @($roots | Where-Object {
$r = $_
-not @($roots | Where-Object { $_ -ne $r -and $r.StartsWith($_ + '\', [StringComparison]::OrdinalIgnoreCase) }).Count
})Project roll-up got the opposite rule: when a path matches several roots, the longest one wins, so a nested work folder rolls its projects up below itself and not below its parent. Both comparisons are case-insensitive, because the path in roots.json may be spelled differently from what the disk reports.
What the save handler did
The roots:save IPC handler in main.js cleans the submitted list, writes the file, and then, in the old version, did this whenever the file changed:
if (!same) {
try { writeRootsFile(ROOTS_FILE, next, nextOff); } catch (e) { error = String(e && e.message || e); }
if (!error) {
dirCache = { at: 0, dirs: [] };
runDiscover({ again: true, withDirs: true });
runMonitor();
}
}That is correct for adding a folder: the new root has to be walked before its projects can appear. It is wasteful for the other two operations the Settings page offers, removing a folder and switching a built-in off. Neither can introduce a project that was not already known. The only thing they change is which entries should disappear, and the registry already prunes those on its normal cycle: both runMonitor and runDiscover are on a 30 minute interval in main.js. The code comment I left says it plainly: a full rescan for a removal was minutes of disk walking for nothing new.
I do not have a timing for that rescan on its own. An earlier story on this blog covers a 3 minute scan on one machine, and I will not claim that number applies here. The argument does not need a number, because the work is zero-gain by construction.
The fix
The handler now computes the effective set before and after, and rescans only if something was gained:
const effBefore = new Set(effectiveRoots(before.roots, rootDefaults(true), null, before.disabled)
.map((p) => p.toLowerCase()));
const gained = effectiveRoots(next, rootDefaults(true), null, nextOff)
.some((p) => !effBefore.has(p.toLowerCase()));
if (!same) {
try { writeRootsFile(ROOTS_FILE, next, nextOff); } catch (e) { error = String(e && e.message || e); }
dirCache = { at: 0, dirs: [] };
if (!error && gained) {
runDiscover({ again: true, withDirs: true });
runMonitor();
}
}
return Object.assign(rootsView(), { changed: !same && !error && gained, error });There are three decisions in there.
Compare effective roots, not the raw lists. My first instinct was to compare next with before.roots. That misses cases where the raw lists differ but the walked set does not. Re-enabling a built-in that was switched off adds a root without touching the user list, and adding a path that is already covered by a default adds nothing to walk. Running both lists through effectiveRoots with the same defaults and the same isDir argument makes the comparison about what the scanner would actually do. Lower-casing both sides matches the case-insensitive dedupe inside effectiveRoots.
Always clear `dirCache`, only sometimes rescan. dirCache is a one-minute cache of the directory listing used by search. If the list of roots changed, a stale cache would keep offering folders from a root the user just removed, so the cache reset moved out of the !error block and no longer depends on gained. The expensive part is the only part that got conditional.
The return value changed too. changed is what the UI uses to decide whether to wait for a refresh. With gained in it, a removal reports no change to wait for, and the renderer text became honest about it: "Removed - its projects leave the list at the next scan (within 30 min)." The same sentence went on the "Turned off" path.
What I accepted
This is a deliberate delay, not a fix for staleness. After removing a folder, its projects remain on the Projects page until the next scheduled scan. For a list that people edit rarely and read constantly, I preferred an instant, silent save and a message that sets the expectation over a progress spinner for work that cannot produce anything new. If that turns out to confuse someone, the cheaper alternative is to filter the registry against the new roots at save time, which needs no walk at all; I did not build that.
Lesson
When a setting can only shrink the world, do not run the code path that exists to grow it. The way to know is to write down the question the expensive operation answers, here "which projects exist under these roots?", and check whether the change can alter the answer upward. For this handler the cheapest correct test was a set difference on the same function the scanner uses, so the check and the walk can never disagree about what a root is.
#electron#nodejs#performance#powershell
Keep reading
Have a project in mind?