Skip to content

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

:art: Refresh virtual block ref when closing box https://github.com/siyuan-note/siyuan/issues/11149#issuecomment-2106254491

Daniel60380f5deeb6
diff --git a/kernel/model/box.go b/kernel/model/box.go
index cb958c4830..fa56aa5679 100644
--- a/kernel/model/box.go
+++ b/kernel/model/box.go
@@ -503,6 +503,10 @@ func genTreeID(tree *parse.Tree) {
func FullReindex() {
task.AppendTask(task.DatabaseIndexFull, fullReindex)
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
+ go func() {
+ sql.WaitForWritingDatabase()
+ ResetVirtualBlockRefCache()
+ }()
task.AppendTaskWithTimeout(task.DatabaseIndexEmbedBlock, 30*time.Second, autoIndexEmbedBlock)
cache.ClearDocsIAL()
cache.ClearBlocksIAL()
diff --git a/kernel/model/index.go b/kernel/model/index.go
index 9a65a2b95a..600554c3bb 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -106,23 +106,26 @@ func listSyFiles(dir string) (ret []string) {
func (box *Box) Unindex() {
task.AppendTask(task.DatabaseIndex, unindex, box.ID)
+ go func() {
+ sql.WaitForWritingDatabase()
+ ResetVirtualBlockRefCache()
+ }()
}
func unindex(boxID string) {
ids := treenode.RemoveBlockTreesByBoxID(boxID)
RemoveRecentDoc(ids)
sql.DeleteBoxQueue(boxID)
-
- go func() {
- sql.WaitForWritingDatabase()
- ResetVirtualBlockRefCache()
- }()
}
func (box *Box) Index() {
task.AppendTask(task.DatabaseIndexRef, removeBoxRefs, box.ID)
task.AppendTask(task.DatabaseIndex, index, box.ID)
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
+ go func() {
+ sql.WaitForWritingDatabase()
+ ResetVirtualBlockRefCache()
+ }()
}
func removeBoxRefs(boxID string) {
@@ -286,8 +289,6 @@ func IndexRefs() {
}
logging.LogInfof("resolved refs [%d] in [%dms]", size, time.Now().Sub(start).Milliseconds())
util.PushStatusBar(fmt.Sprintf(Conf.Language(55), i))
-
- ResetVirtualBlockRefCache()
}
var indexEmbedBlockLock = sync.Mutex{}
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 17c90399d2..d88991db32 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -51,6 +51,7 @@ import (
"github.com/siyuan-note/logging"
"github.com/siyuan-note/siyuan/kernel/conf"
"github.com/siyuan-note/siyuan/kernel/filesys"
+ "github.com/siyuan-note/siyuan/kernel/sql"
"github.com/siyuan-note/siyuan/kernel/task"
"github.com/siyuan-note/siyuan/kernel/treenode"
"github.com/siyuan-note/siyuan/kernel/util"
@@ -649,6 +650,10 @@ func checkoutRepo(id string) {
task.AppendTask(task.DatabaseIndexFull, fullReindex)
task.AppendTask(task.DatabaseIndexRef, IndexRefs)
+ go func() {
+ sql.WaitForWritingDatabase()
+ ResetVirtualBlockRefCache()
+ }()
task.AppendTask(task.ReloadUI, util.ReloadUIResetScroll)
if syncEnabled {
diff --git a/kernel/model/virutalref.go b/kernel/model/virutalref.go
index f68b3c7bb1..e1ba2f4fed 100644
--- a/kernel/model/virutalref.go
+++ b/kernel/model/virutalref.go
@@ -106,8 +106,8 @@ func CacheVirtualBlockRefJob() {
task.AppendTask(task.CacheVirtualBlockRef, ResetVirtualBlockRefCache)
}
-func cacheVirtualBlockRef() {
- virtualBlockRefCache.Del("virtual_ref")
+func ResetVirtualBlockRefCache() {
+ virtualBlockRefCache.Clear()
if !Conf.Editor.VirtualBlockRef {
return
}
@@ -116,11 +116,6 @@ func cacheVirtualBlockRef() {
virtualBlockRefCache.Set("virtual_ref", keywords, 1)
}
-func ResetVirtualBlockRefCache() {
- virtualBlockRefCache.Clear()
- cacheVirtualBlockRef()
-}
-
func AddVirtualBlockRefInclude(keyword []string) {
if 1 > len(keyword) {
return