From 9474f558adbb0464a9b9900c44f07cda4d574cb0 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 9 Jan 2023 17:37:28 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E8=87=AA=E5=8A=A8=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E7=B4=A2=E5=BC=95=20https://github.?= =?UTF-8?q?com/siyuan-note/siyuan/issues/7016?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/model/transaction.go | 7 +++---- kernel/treenode/blocktree.go | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/kernel/model/transaction.go b/kernel/model/transaction.go index 8b3f42be5..aad8d7b51 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 6d29430fe..cbf59c79f 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()