Skip to content

Commit e894411

Browse files
fix(doctor): replace filepath.Walk with known-path lookup in stale-sql-server-info check
Same fix pattern as stale-dolt-port: enumerate known .beads/dolt/.dolt/ locations via rigs.json + top-level directory scan instead of walking the entire town root. Eliminates ~40s of IO on Docker bind mounts (macOS VirtioFS) with 180k+ files. Co-Authored-By: Claude
1 parent c553a2c commit e894411

1 file changed

Lines changed: 37 additions & 15 deletions

File tree

internal/doctor/stale_sql_server_info_check.go

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package doctor
22

33
import (
4+
"encoding/json"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -35,31 +36,52 @@ func NewStaleSQLServerInfoCheck() *StaleSQLServerInfoCheck {
3536
func (c *StaleSQLServerInfoCheck) Run(ctx *CheckContext) *CheckResult {
3637
c.staleFiles = nil
3738

38-
// Find all sql-server.info files under the town root
39+
// Find sql-server.info files in known .beads/dolt/.dolt/ locations.
40+
// Avoids filepath.Walk over the entire town root, which is extremely slow
41+
// on Docker bind mounts (macOS VirtioFS).
3942
var details []string
40-
_ = filepath.Walk(ctx.TownRoot, func(path string, info os.FileInfo, err error) error {
41-
if err != nil {
42-
return nil
43-
}
44-
// Skip .git directories and node_modules
45-
if info.IsDir() && (info.Name() == ".git" || info.Name() == "node_modules") {
46-
return filepath.SkipDir
43+
44+
locations := []string{
45+
filepath.Join(ctx.TownRoot, ".beads", "dolt", ".dolt", "sql-server.info"),
46+
}
47+
48+
// Collect rig names from rigs.json and top-level directories.
49+
rigNames := make(map[string]struct{})
50+
rigsConfig := filepath.Join(ctx.TownRoot, "mayor", "rigs.json")
51+
if data, err := os.ReadFile(rigsConfig); err == nil {
52+
var rigs struct {
53+
Rigs map[string]struct{} `json:"rigs"`
4754
}
48-
if info.Name() != "sql-server.info" {
49-
return nil
55+
if json.Unmarshal(data, &rigs) == nil {
56+
for name := range rigs.Rigs {
57+
rigNames[name] = struct{}{}
58+
}
5059
}
51-
// Only care about files inside .dolt directories
52-
if !strings.Contains(path, ".dolt") {
53-
return nil
60+
}
61+
// Also scan top-level directories as fallback (handles rigs not yet in rigs.json).
62+
if entries, err := os.ReadDir(ctx.TownRoot); err == nil {
63+
for _, e := range entries {
64+
if e.IsDir() && !strings.HasPrefix(e.Name(), ".") {
65+
rigNames[e.Name()] = struct{}{}
66+
}
5467
}
68+
}
69+
for rigName := range rigNames {
70+
locations = append(locations,
71+
filepath.Join(ctx.TownRoot, rigName, ".beads", "dolt", ".dolt", "sql-server.info"),
72+
)
73+
}
5574

75+
for _, path := range locations {
76+
if _, err := os.Stat(path); err != nil {
77+
continue
78+
}
5679
if c.isStale(path) {
5780
c.staleFiles = append(c.staleFiles, path)
5881
relPath, _ := filepath.Rel(ctx.TownRoot, path)
5982
details = append(details, fmt.Sprintf("Stale sql-server.info: %s", relPath))
6083
}
61-
return nil
62-
})
84+
}
6385

6486
if len(c.staleFiles) == 0 {
6587
return &CheckResult{

0 commit comments

Comments
 (0)