Experience
Projects
My Stack
Case studies
Contact me
Open my CV

·5 min read

My workspace on G: was invisible to DailyBrief, and the fix exposed a 3 minute scan

My project list was missing the one place I actually work. DailyBrief showed projects from Desktop, Documents and a few other folders under my user profile, and my real workspace lives on G:\Desktop, a different drive. Nothing under it ever appeared. When I fixed that by letting the app scan any folder I choose, the next problem was waiting: the scan I already had was slow enough to make a bigger one painful.

Project
DailyBrief
Date
Oct 2026
Stack
PowerShell 5.1, Electron, Node.js
Commit
44a43b7

The roots were hardcoded in three places

DailyBrief watches where I have been working: it walks a few folders, looks at files written in the last 14 days, and rolls each file's directory up to a project. Before this commit, monitor.ps1, discover-dirs.ps1 and discover-projects.ps1 each carried their own copy of the same list:

powershell
$roots = @(
    "$env:USERPROFILE\OneDrive\Desktop",
    "$env:USERPROFILE\OneDrive\Documents",
    "$env:USERPROFILE\Desktop",
    "$env:USERPROFILE\Documents",
    "$env:USERPROFILE\Downloads",
    "$env:USERPROFILE\source",
    "$env:USERPROFILE\projects"
) | Where-Object { Test-Path $_ }

Every entry hangs off the user profile. A work folder on G: simply was not in any list, so there was nothing to fix by tweaking a path. The comment I left in the new core/roots.ps1 says it directly: hardcoding only the defaults is what left a G:\Desktop workspace invisible.

The three copies were also slightly different. The projects script left Downloads out, the monitor included it. That difference was deliberate, but it is the kind of thing that drifts when it is copy-pasted. So the first change was one function, Get-WorkRoots, that every script dot-sources. It reads roots.json from the data folder (written by a new Settings section), appends the Windows defaults, removes case-insensitive duplicates and drops anything that does not exist. A -WithDownloads switch keeps the old per-script difference explicit instead of accidental.

User folders come first and the built-in ones can be switched off, stored in a disabled list. If the same folder is both a user entry and a disabled default, the user entry wins.

Why a bigger scan was a problem

The old monitor loop was this:

powershell
Get-ChildItem $root -Recurse -File -ErrorAction SilentlyContinue |
    Where-Object { $_.LastWriteTime -gt $cutoff -and $_.FullName -notmatch $exclude } |
    Select-Object -First 500

It reads fine, and it is the expensive shape. -Recurse enumerates every folder, including node_modules, .git and build output. The $exclude regex only throws results away after the enumeration already paid for them. The header comment in core/walk.ps1 records what that meant on the new root: three minutes per monitor run on G:\Desktop. I did not re-measure it for this write-up; that number is from my own note in the commit.

Adding user-chosen folders to that loop would have multiplied the cost by something I do not control, because I do not control what is in someone's folder.

The pruned walk

Get-RecentFiles replaces -Recurse with an explicit stack and never pushes certain folders onto it:

powershell
$script:PruneNameRe = '^(node_modules|\.git|\.svn|\.hg|vendor|dist|build|bin|obj|\.next|\.nuxt|\.output|\.turbo|\.cache|...|\$Recycle\.Bin|System Volume Information)$'

foreach ($e in $dir.EnumerateFileSystemInfos()) {
    if ($e -is [System.IO.DirectoryInfo]) {
        if (($e.Attributes -band $reparse) -ne 0) { continue }
        if ($e.Name -match $script:PruneNameRe) { continue }
        ...
        $stack.Push($e)
    } elseif ($e.LastWriteTime -gt $Since) {
        ...
    }
}

Three details matter. First, matching on the leaf name means a node_modules is skipped before any of its contents are listed. Second, EnumerateFileSystemInfos() returns directory entries that already carry LastWriteTime, so there is no extra stat call per file. Third, reparse points (junctions and symlinks) are not followed, since they either loop or leave the root. Access-denied and vanished folders are caught and skipped rather than fatal, and -Max stops the walk at 500 hits like the old Select-Object -First 500 did, except it actually stops walking.

The fallback walk in discover-dirs.ps1 was already pruning, but with its own inline copy of the logic. It now calls the same function, so there is one walk to get right.

Nested roots and the longest match

Once folders are configurable, someone will add G:\Desktop\work while G:\Desktop is already a root. Two things go wrong. The same file gets counted under both walks, and the project roll-up (root plus at most two segments) picks whichever root it hits first. The fix is two small rules:

powershell
$walkRoots = @($roots | Where-Object {
    $r = $_
    -not @($roots | Where-Object { $_ -ne $r -and
        $r.StartsWith($_ + '\', [StringComparison]::OrdinalIgnoreCase) }).Count
})

Only outermost roots are walked, and Get-ProjectDir picks the longest root that matches, case-insensitively, because roots.json may spell a path differently from what the disk reports. The first rule avoids double counting, the second makes a nested folder roll up below itself instead of below its parent.

The last fix: do not rescan on removal

The follow-up commit, 720259c, is the one I like best because it deletes work. After saving roots, the app ran a full rediscovery every time. But removing a folder cannot reveal anything new; its projects just need to disappear. In main.js I compare the effective roots before and after and only rescan if the walk gained a folder:

js
const gained = effectiveRoots(next, rootDefaults(true), null, nextOff)
  .some((p) => !effBefore.has(p.toLowerCase()));

Removed projects drop out at the regular 30 minute scan, and the UI now says so instead of promising instant results. The commit's own comment calls the old behaviour minutes of disk walking for nothing new.

What I took from it

The bug looked like a missing folder and was really a missing abstraction. Once the list lived in one place, the cost of scanning it became visible, because suddenly the number of roots was the user's choice. src/roots.js has tests in test/roots.test.js for the parts that are easy to get subtly wrong: BOMs in the JSON file, junk entries, drive roots like G:\ that I refuse, and case-insensitive de-duplication.

#powershell#filesystem#performance#electron

Keep reading

Have a project in mind?