Skip to content

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

:art: 自动校验数据库索引 https://github.com/siyuan-note/siyuan/issues/7016

Liang Ding9474f558adbb
diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go
index 8b3f42be52..aad8d7b51b 100644
--- a/kernel/model/transaction.go
+++ b/kernel/model/transaction.go
@@ -1253,10 +1253,9 @@ func autoFixIndex() {
})
size := len(paths)
- for i, p := range paths {
- if nil == treenode.GetBlockTreeRootByPath(box.ID, p) {
- reindexTreeByPath(box.ID, p, i, size)
- }
+ missingPaths := treenode.GetNotExistPaths(box.ID, paths)
+ for i, p := range missingPaths {
+ reindexTreeByPath(box.ID, p, i, size)
}
}
diff --git a/kernel/treenode/blocktree.go b/kernel/treenode/blocktree.go
index 6d29430fe7..cbf59c79f2 100644
--- a/kernel/treenode/blocktree.go
+++ b/kernel/treenode/blocktree.go
@@ -116,6 +116,27 @@ func CeilBlockCount(count int) int {
return 10000*100 + 1
}
+func GetNotExistPaths(boxID string, paths []string) (ret []string) {
+ blockTreesLock.Lock()
+ defer blockTreesLock.Unlock()
+
+ pathsMap := map[string]bool{}
+ for _, path := range paths {
+ pathsMap[path] = true
+ }
+
+ for _, blockTree := range blockTrees {
+ if blockTree.BoxID != boxID {
+ continue
+ }
+
+ if !pathsMap[blockTree.Path] {
+ ret = append(ret, blockTree.Path)
+ }
+ }
+ return
+}
+
func GetBlockTreeRootByPath(boxID, path string) *BlockTree {
blockTreesLock.Lock()
defer blockTreesLock.Unlock()