went from 160k os.Stat to 90 on my box. duh

This commit is contained in:
Jeff Carr 2024-12-02 05:14:52 -06:00
parent be026e8edc
commit f5d41d782a
4 changed files with 75 additions and 14 deletions

1
.protobuf Normal file
View File

@ -0,0 +1 @@
forgeConfig.proto

45
goDebCheck.go Normal file
View File

@ -0,0 +1,45 @@
package forgepb
import (
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
// this is a final check to make sure, before pushing
// a golang repo, that the go.sum file has the correct
// and current version of every package
//
// it re-scans the go.sum file. DOES NOT MODIFY ANYTHING
// this is the last thing to run to double check everything
// before 'git tag' or git push --tags
func (f *Forge) FinalGoDepsCheck(check *gitpb.Repo) bool {
var good bool = true
if check == nil {
log.Info("boo, check == nil")
return false
}
// clear out the protobuf and rescan from the file
check.GoDeps = nil
check.ParseGoSum()
log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen())
deps := check.GoDeps.SortByGoPath()
for deps.Scan() {
depRepo := deps.Next()
found := f.Repos.FindByGoPath(depRepo.GetGoPath())
if found == nil {
log.Info("not found:", depRepo.GetGoPath())
return false
}
// log.Info("found dep", depRepo.GetGoPath())
if depRepo.GetVersion() != found.GetMasterVersion() {
if f.IsReadOnly(depRepo.GetGoPath()) {
log.Printf("%-48s ok error %10s vs %10s (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion())
} else {
log.Printf("%-48s error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion())
good = false
}
}
}
return good
}

View File

@ -2,6 +2,7 @@ package forgepb
import ( import (
"errors" "errors"
"fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
@ -12,7 +13,9 @@ import (
) )
func (f *Forge) ScanGoSrc() (bool, error) { func (f *Forge) ScanGoSrc() (bool, error) {
dirs, err := gitDirectories(f.goSrc) log.Info("pre dir walk")
dirs, err := gitDirectoriesNew(f.goSrc)
log.Info("post dir walk", len(dirs))
if err != nil { if err != nil {
return false, err return false, err
} }
@ -28,23 +31,34 @@ func (f *Forge) ScanGoSrc() (bool, error) {
return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir) return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir)
} }
} }
log.Info("pre rill")
f.rillScanDirs(gopaths) f.rillScanDirs(gopaths)
/*
for _, dir := range dirs {
if strings.HasPrefix(dir, f.goSrc) {
gopath := strings.TrimPrefix(dir, f.goSrc)
gopath = strings.Trim(gopath, "/")
repo, err := f.Repos.NewGoPath(f.goSrc, gopath)
} else {
log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir)
}
}
*/
return true, err return true, err
} }
func gitDirectories(srcDir string) ([]string, error) { // doesn't enter the directory any further when it finds a .git/
// not stupid like my old version
func gitDirectoriesNew(srcDir string) ([]string, error) {
var all []string
err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error {
if err != nil {
// Handle possible errors, like permission issues
fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err)
return err
}
gitdir := filepath.Join(path, ".git")
_, err2 := os.Stat(gitdir)
if !os.IsNotExist(err2) {
all = append(all, path)
return filepath.SkipDir
}
return nil
})
return all, err
}
func gitDirectoriesOld(srcDir string) ([]string, error) {
var all []string var all []string
err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {

View File

@ -44,6 +44,7 @@ func Init() *Forge {
} }
f.Machine.InitWit() f.Machine.InitWit()
log.Info("forge pre scan ", f.Repos.Len(), "repos in", f.goSrc)
f.ScanGoSrc() f.ScanGoSrc()
log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc) log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc)
return f return f