Skip to content

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

:art: Rebuilding database block relations when importing .sy.zip and rebuilding indexes https://github.com/siyuan-note/siyuan/issues/10959

Daniel7d680ed39192
diff --git a/kernel/model/import.go b/kernel/model/import.go
index 641e0cea14..938cf00e98 100644
--- a/kernel/model/import.go
+++ b/kernel/model/import.go
@@ -281,6 +281,10 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
}
return ast.WalkContinue
})
+
+ // 关联数据库和块
+ avNodes := tree.Root.ChildrenByType(ast.NodeAttributeView)
+ av.BatchUpsertBlockRel(avNodes)
}
}
diff --git a/kernel/model/index.go b/kernel/model/index.go
index 710f77330d..3a325368a8 100644
--- a/kernel/model/index.go
+++ b/kernel/model/index.go
@@ -36,6 +36,7 @@ import (
"github.com/siyuan-note/eventbus"
"github.com/siyuan-note/filelock"
"github.com/siyuan-note/logging"
+ "github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/cache"
"github.com/siyuan-note/siyuan/kernel/filesys"
"github.com/siyuan-note/siyuan/kernel/sql"
@@ -143,6 +144,7 @@ func index(boxID string) {
poolSize = 4
}
waitGroup := &sync.WaitGroup{}
+ var avNodes []*ast.Node
p, _ := ants.NewPoolWithFunc(poolSize, func(arg interface{}) {
defer waitGroup.Done()
@@ -168,6 +170,10 @@ func index(boxID string) {
}
}
+ lock.Lock()
+ avNodes = append(avNodes, tree.Root.ChildrenByType(ast.NodeAttributeView)...)
+ lock.Unlock()
+
cache.PutDocIAL(file.path, docIAL)
treenode.IndexBlockTree(tree)
sql.IndexTreeQueue(tree)
@@ -191,6 +197,9 @@ func index(boxID string) {
waitGroup.Wait()
p.Release()
+ // 关联数据库和块
+ av.BatchUpsertBlockRel(avNodes)
+
box.UpdateHistoryGenerated() // 初始化历史生成时间为当前时间
end := time.Now()
elapsed := end.Sub(start).Seconds()