Skip to content

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

:art: Improve kernel stability by eliminating some data races https://github.com/siyuan-note/siyuan/issues/9842

Daniel8c4adbc48a9f
diff --git a/kernel/model/ocr.go b/kernel/model/ocr.go
index f131716f9c..c8cb03c0a3 100644
--- a/kernel/model/ocr.go
+++ b/kernel/model/ocr.go
@@ -17,6 +17,8 @@ import (
)
func OCRAssetsJob() {
+ util.WaitForTesseractInit()
+
if !util.TesseractEnabled {
return
}
@@ -25,6 +27,10 @@ func OCRAssetsJob() {
}
func autoOCRAssets() {
+ if !util.TesseractEnabled {
+ return
+ }
+
defer logging.Recover()
assetsPath := util.GetDataAssetsAbsPath()
diff --git a/kernel/util/tesseract.go b/kernel/util/tesseract.go
index 9f56c19c91..7136bb616b 100644
--- a/kernel/util/tesseract.go
+++ b/kernel/util/tesseract.go
@@ -26,6 +26,7 @@ import (
"strconv"
"strings"
"sync"
+ "sync/atomic"
"time"
"github.com/88250/gulu"
@@ -136,9 +137,21 @@ func Tesseract(imgAbsPath string) string {
return ret
}
+var tesseractInited = atomic.Bool{}
+
+func WaitForTesseractInit() {
+ for {
+ if tesseractInited.Load() {
+ return
+ }
+ time.Sleep(time.Second)
+ }
+}
+
func InitTesseract() {
ver := getTesseractVer()
if "" == ver {
+ tesseractInited.Store(true)
return
}
@@ -146,6 +159,7 @@ func InitTesseract() {
if 1 > len(langs) {
logging.LogWarnf("no tesseract langs found")
TesseractEnabled = false
+ tesseractInited.Store(true)
return
}
@@ -162,6 +176,7 @@ func InitTesseract() {
TesseractEnabled = enabledBool
if !enabledBool {
logging.LogInfof("tesseract-ocr disabled by env")
+ tesseractInited.Store(true)
return
}
}
@@ -169,6 +184,7 @@ func InitTesseract() {
TesseractLangs = filterTesseractLangs(langs)
logging.LogInfof("tesseract-ocr enabled [ver=%s, maxSize=%s, langs=%s]", ver, humanize.Bytes(TesseractMaxSize), strings.Join(TesseractLangs, "+"))
+ tesseractInited.Store(true)
}
func filterTesseractLangs(langs []string) (ret []string) {