An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: Avoid long wait when exiting while data repo purge is in progress https://github.com/siyuan-note/siyuan/issues/17711
Daniel8569d374b98c
diff --git a/kernel/go.mod b/kernel/go.modindex c9aa6c38e4..c871852ad3 100644--- a/kernel/go.mod+++ b/kernel/go.mod@@ -68,7 +68,7 @@ require (github.com/sashabaranov/go-openai v1.41.2github.com/shirou/gopsutil/v4 v4.26.4github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17- github.com/siyuan-note/dejavu v0.0.0-20260529092727-2b5e57a676af+ github.com/siyuan-note/dejavu v0.0.0-20260612083615-9c45cefc9285github.com/siyuan-note/encryption v0.0.0-20251120032857-3ddc3c2cc49fgithub.com/siyuan-note/eventbus v0.0.0-20260530125927-d77c74260dcegithub.com/siyuan-note/filelock v0.0.0-20260411141728-bf44452627c0diff --git a/kernel/go.sum b/kernel/go.sumindex 83b42db554..159b493781 100644--- a/kernel/go.sum+++ b/kernel/go.sum@@ -391,8 +391,8 @@ github.com/shurcooL/gofontwoff v0.0.0-20181114050219-180f79e6909d/go.mod h1:05Utgithub.com/simplereach/timeutils v1.2.0/go.mod h1:VVbQDfN/FHRZa1LSqcwo4kNZ62OOyqLLGQKYB3pB0Q8=github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17 h1:cZbH1QcW/LWYtaKBv2i0O96qVm6HXKeEE3Z74VYdUHM=github.com/siyuan-note/dataparser v0.0.0-20260115084335-b57cb8bc7c17/go.mod h1:zE2SJ4t+2lFAeLgmhi27YtfzdyOWh3l9DXXUr9m/xU0=-github.com/siyuan-note/dejavu v0.0.0-20260529092727-2b5e57a676af h1:UeK/zRYGFlBaBhAM0tCa84criQTB5Qx3PdUvGoBj97I=-github.com/siyuan-note/dejavu v0.0.0-20260529092727-2b5e57a676af/go.mod h1:Wal8Y/RgYRINa0jyHdN3XqPUh0GGEcr3QfNVcK9Ci2w=+github.com/siyuan-note/dejavu v0.0.0-20260612083615-9c45cefc9285 h1:1A9XHNx4JPeOBUoR0eGm7UBgXlRJwwheu1cYMGbrCfM=+github.com/siyuan-note/dejavu v0.0.0-20260612083615-9c45cefc9285/go.mod h1:Wal8Y/RgYRINa0jyHdN3XqPUh0GGEcr3QfNVcK9Ci2w=github.com/siyuan-note/encryption v0.0.0-20251120032857-3ddc3c2cc49f h1:HSgJKIAMgokJDAvBBfRj47SzRSm6mNGssY0Wv7rcEtg=github.com/siyuan-note/encryption v0.0.0-20251120032857-3ddc3c2cc49f/go.mod h1:JE3S9VuJqTggyfhjesNDuqvqrRvwG3IctFjXXchLx1M=github.com/siyuan-note/eventbus v0.0.0-20260530125927-d77c74260dce h1:356bfC3pucxXuYpZIwaQ3viVCbq5RbRuvBhb4xtoBR0=diff --git a/kernel/model/conf.go b/kernel/model/conf.goindex 3753992b15..a34686607c 100644--- a/kernel/model/conf.go+++ b/kernel/model/conf.go@@ -765,6 +765,8 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {FlushTxQueue()if !force {+ cancelPurge()+// Stop kernel plugins early in shutdownif OnKernelPluginsStop != nil {OnKernelPluginsStop()diff --git a/kernel/model/repository.go b/kernel/model/repository.goindex bc8e9167e9..da6f91867d 100644--- a/kernel/model/repository.go+++ b/kernel/model/repository.go@@ -18,6 +18,7 @@ package modelimport ("bytes"+ "context""crypto/rand""crypto/sha1""crypto/sha256"@@ -72,6 +73,9 @@ func AutoPurgeRepoJob() {var (autoPurgeRepoAfterFirstSync = falselastAutoPurgeRepo = time.Time{}++ purgeCancelMu sync.Mutex+ purgeCancel context.CancelFunc)func autoPurgeRepo(cron bool) {@@ -166,7 +170,30 @@ func autoPurgeRepo(cron bool) {return}- _, err = repo.Purge(retentionIndexIDs...)+ purgeCancelMu.Lock()+ var ctx context.Context+ ctx, purgeCancel = context.WithCancel(context.Background())+ cancelCtx := ctx+ purgeCancelMu.Unlock()+ defer func() {+ purgeCancelMu.Lock()+ if nil != purgeCancel {+ purgeCancel()+ purgeCancel = nil+ }+ purgeCancelMu.Unlock()+ }()++ _, err = repo.Purge(cancelCtx, retentionIndexIDs...)+}++func cancelPurge() {+ purgeCancelMu.Lock()+ defer purgeCancelMu.Unlock()+ if nil != purgeCancel {+ purgeCancel()+ purgeCancel = nil+ }}func GetRepoFile(fileID string) (ret []byte, p string, err error) {@@ -876,7 +903,7 @@ func PurgeRepo() (err error) {return}- stat, err := repo.Purge()+ stat, err := repo.Purge(context.Background())if err != nil {return}