Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:recycle: kernel/search/find: modernize with wg.Go (#17289)

iliyac3808f4e775d
diff --git a/kernel/search/find.go b/kernel/search/find.go
index 104889e79d..5c9e667df6 100644
--- a/kernel/search/find.go
+++ b/kernel/search/find.go
@@ -71,19 +71,15 @@ func FindAllMatches(root string, targets []string) []Match {
var collectWg sync.WaitGroup
var matches []Match
- collectWg.Add(1)
- go func() {
- defer collectWg.Done()
+ collectWg.Go(func() {
for m := range results {
matches = append(matches, m)
}
- }()
+ })
numWorkers := runtime.NumCPU()
- for i := 0; i < numWorkers; i++ {
- wg.Add(1)
- go func() {
- defer wg.Done()
+ for range numWorkers {
+ wg.Go(func() {
for p := range jobs {
hits := scanFileForTargets(p, patternIndex, maxLen)
if len(hits) > 0 {
@@ -92,7 +88,7 @@ func FindAllMatches(root string, targets []string) []Match {
}
}
}
- }()
+ })
}
_ = filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error {