mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-23 16:56:10 +01:00
This commit is contained in:
parent
07a5e7501a
commit
5a09669d3a
1 changed files with 37 additions and 0 deletions
|
|
@ -1238,6 +1238,29 @@ func autoFixIndex() {
|
|||
autoFixLock.Lock()
|
||||
defer autoFixLock.Unlock()
|
||||
|
||||
// 根据文件系统补全块树
|
||||
boxes := Conf.GetOpenedBoxes()
|
||||
for _, box := range boxes {
|
||||
boxPath := filepath.Join(util.DataDir, box.ID)
|
||||
var paths []string
|
||||
filepath.Walk(boxPath, func(path string, info os.FileInfo, err error) error {
|
||||
if !info.IsDir() && filepath.Ext(path) == ".sy" {
|
||||
p := path[len(boxPath):]
|
||||
p = filepath.ToSlash(p)
|
||||
paths = append(paths, p)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
size := len(paths)
|
||||
for i, p := range paths {
|
||||
if nil == treenode.GetBlockTreeRootByPath(box.ID, p) {
|
||||
reindexTreeByPath(box.ID, p, i, size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 对比块树和数据库并订正数据库
|
||||
rootUpdatedMap := treenode.GetRootUpdated()
|
||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
||||
if nil == err {
|
||||
|
|
@ -1273,6 +1296,7 @@ func autoFixIndex() {
|
|||
}
|
||||
}
|
||||
|
||||
// 去除重复的数据库块记录
|
||||
duplicatedRootIDs := sql.GetDuplicatedRootIDs()
|
||||
size := len(duplicatedRootIDs)
|
||||
for i, rootID := range duplicatedRootIDs {
|
||||
|
|
@ -1287,6 +1311,15 @@ func autoFixIndex() {
|
|||
}
|
||||
}
|
||||
|
||||
func reindexTreeByPath(box, p string, i, size int) {
|
||||
tree, err := LoadTree(box, p)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
reindexTree0(tree, i, size)
|
||||
}
|
||||
|
||||
func reindexTree(rootID string, i, size int) {
|
||||
root := treenode.GetBlockTree(rootID)
|
||||
if nil == root {
|
||||
|
|
@ -1303,6 +1336,10 @@ func reindexTree(rootID string, i, size int) {
|
|||
return
|
||||
}
|
||||
|
||||
reindexTree0(tree, i, size)
|
||||
}
|
||||
|
||||
func reindexTree0(tree *parse.Tree, i, size int) {
|
||||
updated := tree.Root.IALAttr("updated")
|
||||
if "" == updated {
|
||||
updated = util.TimeFromID(tree.Root.ID)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue