mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-21 07:46:09 +01:00
Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
751c1df6b6
2 changed files with 53 additions and 0 deletions
|
|
@ -1255,6 +1255,12 @@ func autoFixIndex() {
|
|||
})
|
||||
|
||||
size := len(paths)
|
||||
|
||||
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
||||
for _, p := range redundantPaths {
|
||||
treenode.RemoveBlockTreesByPath(p)
|
||||
}
|
||||
|
||||
missingPaths := treenode.GetNotExistPaths(box.ID, paths)
|
||||
for i, p := range missingPaths {
|
||||
reindexTreeByPath(box.ID, p, i, size)
|
||||
|
|
|
|||
|
|
@ -116,6 +116,31 @@ func CeilBlockCount(count int) int {
|
|||
return 10000*100 + 1
|
||||
}
|
||||
|
||||
func GetRedundantPaths(boxID string, paths []string) (ret []string) {
|
||||
pathsMap := map[string]bool{}
|
||||
for _, path := range paths {
|
||||
pathsMap[path] = true
|
||||
}
|
||||
|
||||
tmp := blockTrees
|
||||
btPathsMap := map[string]bool{}
|
||||
for _, blockTree := range tmp {
|
||||
if blockTree.BoxID != boxID {
|
||||
continue
|
||||
}
|
||||
|
||||
btPathsMap[blockTree.Path] = true
|
||||
}
|
||||
|
||||
for p, _ := range btPathsMap {
|
||||
if !pathsMap[p] {
|
||||
ret = append(ret, p)
|
||||
}
|
||||
}
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
return
|
||||
}
|
||||
|
||||
func GetNotExistPaths(boxID string, paths []string) (ret []string) {
|
||||
pathsMap := map[string]bool{}
|
||||
for _, path := range paths {
|
||||
|
|
@ -132,6 +157,7 @@ func GetNotExistPaths(boxID string, paths []string) (ret []string) {
|
|||
ret = append(ret, blockTree.Path)
|
||||
}
|
||||
}
|
||||
ret = gulu.Str.RemoveDuplicatedElem(ret)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -191,6 +217,24 @@ func RemoveBlockTreesByRootID(rootID string) {
|
|||
ids = append(ids, b.RootID)
|
||||
}
|
||||
}
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
delete(blockTrees, id)
|
||||
}
|
||||
blockTreesChanged = true
|
||||
}
|
||||
|
||||
func RemoveBlockTreesByPath(path string) {
|
||||
blockTreesLock.Lock()
|
||||
defer blockTreesLock.Unlock()
|
||||
|
||||
var ids []string
|
||||
for _, b := range blockTrees {
|
||||
if b.Path == path {
|
||||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
delete(blockTrees, id)
|
||||
}
|
||||
|
|
@ -207,6 +251,7 @@ func RemoveBlockTreesByPathPrefix(pathPrefix string) {
|
|||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
delete(blockTrees, id)
|
||||
}
|
||||
|
|
@ -222,6 +267,7 @@ func RemoveBlockTreesByBoxID(boxID string) (ids []string) {
|
|||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
delete(blockTrees, id)
|
||||
}
|
||||
|
|
@ -247,6 +293,7 @@ func ReindexBlockTree(tree *parse.Tree) {
|
|||
ids = append(ids, b.ID)
|
||||
}
|
||||
}
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
delete(blockTrees, id)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue