Skip to content

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

:art: Improve indexing completeness when exiting https://github.com/siyuan-note/siyuan/issues/12039

Daniel07d2930739de
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index cd1585e071..e4e1015016 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -611,7 +611,7 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
closeUserGuide()
// Improve indexing completeness when exiting https://github.com/siyuan-note/siyuan/issues/12039
- sql.WaitForWritingDatabase()
+ sql.WaitForWritingDatabaseIn(200 * time.Millisecond)
util.IsExiting.Store(true)
waitSecondForExecInstallPkg := false
diff --git a/kernel/sql/queue.go b/kernel/sql/queue.go
index 2ba884896d..27d5447987 100644
--- a/kernel/sql/queue.go
+++ b/kernel/sql/queue.go
@@ -61,7 +61,7 @@ func FlushTxJob() {
func WaitForWritingDatabase() {
var printLog bool
var lastPrintLog bool
- for i := 0; isWritingDatabase(); i++ {
+ for i := 0; isWritingDatabase(util.SQLFlushInterval + 50*time.Millisecond); i++ {
time.Sleep(50 * time.Millisecond)
if 200 < i && !printLog { // 10s 后打日志
logging.LogWarnf("database is writing: \n%s", logging.ShortStack())
@@ -74,8 +74,14 @@ func WaitForWritingDatabase() {
}
}
-func isWritingDatabase() bool {
- time.Sleep(util.SQLFlushInterval + 50*time.Millisecond)
+func WaitForWritingDatabaseIn(duration time.Duration) {
+ for i := 0; isWritingDatabase(duration); i++ {
+ time.Sleep(50 * time.Millisecond)
+ }
+}
+
+func isWritingDatabase(d time.Duration) bool {
+ time.Sleep(d)
dbQueueLock.Lock()
defer dbQueueLock.Unlock()
if 0 < len(operationQueue) || isWriting {