Skip to content

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

:recycle: min(runtime.NumCPU(), n)

Daniel1667adb1c4a0
diff --git a/kernel/model/asset_content.go b/kernel/model/asset_content.go
index bfaf519bfa..b129e37799 100644
--- a/kernel/model/asset_content.go
+++ b/kernel/model/asset_content.go
@@ -793,12 +793,7 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
return
}
- // initialize go-pdfium with number of available cores
- // we fire up the complete worker pool for maximum performance
- cores := runtime.NumCPU()
- if 4 < cores {
- cores = 4 // Limit memory usage
- }
+ cores := min(runtime.NumCPU(), 4) // Limit memory usage
pool, err := webassembly.Init(webassembly.Config{
MinIdle: cores,
diff --git a/kernel/model/index.go b/kernel/model/index.go
index 644d6c9bc2..5fe5bf9a47 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -152,10 +152,7 @@ func indexBox(boxID string) {
lock := sync.Mutex{}
util.PushStatusBar(fmt.Sprintf("["+html.EscapeString(box.Name)+"] "+Conf.Language(64), len(files)))
- poolSize := runtime.NumCPU()
- if 4 < poolSize {
- poolSize = 4
- }
+ poolSize := min(runtime.NumCPU(), 4)
waitGroup := &sync.WaitGroup{}
var avNodes []*ast.Node
p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {