mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-27 11:58:49 +01:00
This commit is contained in:
parent
dc4b5accfb
commit
88f716b5d6
7 changed files with 90 additions and 48 deletions
|
|
@ -523,30 +523,6 @@ func genTreeID(tree *parse.Tree) {
|
|||
return
|
||||
}
|
||||
|
||||
func ReindexTree(path string) (err error) {
|
||||
if !strings.HasPrefix(path, "/data/") {
|
||||
return errors.New("path must start with /data/")
|
||||
}
|
||||
|
||||
part := strings.TrimPrefix(path, "/data/")
|
||||
idx := strings.Index(part, "/")
|
||||
if 0 > idx {
|
||||
return errors.New("parse box failed")
|
||||
}
|
||||
box := part[:idx]
|
||||
|
||||
p := strings.TrimPrefix(path, "/data/"+box)
|
||||
tree, err := LoadTree(box, p)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
treenode.ReindexBlockTree(tree)
|
||||
sql.UpsertTreeQueue(tree)
|
||||
sql.WaitForWritingDatabase()
|
||||
return
|
||||
}
|
||||
|
||||
func FullReindex() {
|
||||
util.PushEndlessProgress(Conf.Language(35))
|
||||
WaitForWritingFiles()
|
||||
|
|
|
|||
|
|
@ -1217,3 +1217,57 @@ func updateRefText(refNode *ast.Node, changedDefNodes map[string]*ast.Node) (cha
|
|||
})
|
||||
return
|
||||
}
|
||||
|
||||
func AutoFixIndex() {
|
||||
for {
|
||||
autoFixIndex()
|
||||
time.Sleep(30 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
func autoFixIndex() {
|
||||
rootUpdated := treenode.GetRootUpdated()
|
||||
for rootID, updated := range rootUpdated {
|
||||
root := sql.GetBlock(rootID)
|
||||
if nil == root {
|
||||
reindexTree(rootID)
|
||||
continue
|
||||
}
|
||||
|
||||
if "" == updated {
|
||||
reindexTree(rootID)
|
||||
continue
|
||||
}
|
||||
|
||||
btUpdated, _ := time.Parse("20060102150405", updated)
|
||||
dbUpdated, _ := time.Parse("20060102150405", root.Updated)
|
||||
if dbUpdated.Before(btUpdated.Add(-1 * time.Minute)) {
|
||||
reindexTree(rootID)
|
||||
continue
|
||||
}
|
||||
|
||||
roots := sql.GetBlockRedundant(rootID)
|
||||
if 1 < len(roots) {
|
||||
reindexTree(rootID)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func reindexTree(rootID string) {
|
||||
root := treenode.GetBlockTree(rootID)
|
||||
if nil == root {
|
||||
logging.LogWarnf("root block not found", rootID)
|
||||
return
|
||||
}
|
||||
|
||||
tree, err := LoadTree(root.BoxID, root.Path)
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
treenode.ReindexBlockTree(tree)
|
||||
sql.UpsertTreeQueue(tree)
|
||||
logging.LogInfof("reindex tree [%s]", tree.ID)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue