mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 03:50:16 +08:00
🎨 尝试定位 未找到 ID 为 xxx 的内容块 https://github.com/siyuan-note/siyuan/issues/7215
This commit is contained in:
parent
bb24468f9b
commit
7aea03db69
@ -30,7 +30,7 @@ import (
|
|||||||
func StartCron() {
|
func StartCron() {
|
||||||
go every(100*time.Millisecond, task.ExecTaskJob)
|
go every(100*time.Millisecond, task.ExecTaskJob)
|
||||||
go every(5*time.Second, task.StatusJob)
|
go every(5*time.Second, task.StatusJob)
|
||||||
go every(3*time.Second, treenode.SaveBlockTreeJob)
|
go every(5*time.Second, treenode.SaveBlockTreeJob)
|
||||||
go every(5*time.Second, model.SyncDataJob)
|
go every(5*time.Second, model.SyncDataJob)
|
||||||
go every(2*time.Hour, model.StatJob)
|
go every(2*time.Hour, model.StatJob)
|
||||||
go every(2*time.Hour, model.RefreshCheckJob)
|
go every(2*time.Hour, model.RefreshCheckJob)
|
||||||
|
@ -108,7 +108,7 @@ func autoFixIndex() {
|
|||||||
|
|
||||||
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
||||||
for _, p := range redundantPaths {
|
for _, p := range redundantPaths {
|
||||||
treenode.RemoveBlockTreesByPath(p)
|
treenode.RemoveBlockTreesByPath(box.ID, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
missingPaths := treenode.GetNotExistPaths(box.ID, paths)
|
missingPaths := treenode.GetNotExistPaths(box.ID, paths)
|
||||||
|
@ -36,7 +36,7 @@ import (
|
|||||||
"github.com/vmihailenco/msgpack/v5"
|
"github.com/vmihailenco/msgpack/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
var blockTrees = sync.Map{}
|
var blockTrees = &sync.Map{}
|
||||||
|
|
||||||
type btSlice struct {
|
type btSlice struct {
|
||||||
data map[string]*BlockTree
|
data map[string]*BlockTree
|
||||||
@ -269,13 +269,13 @@ func RemoveBlockTreesByRootID(rootID string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveBlockTreesByPath(path string) {
|
func RemoveBlockTreesByPath(boxID, path string) {
|
||||||
var ids []string
|
var ids []string
|
||||||
blockTrees.Range(func(key, value interface{}) bool {
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
slice := value.(*btSlice)
|
slice := value.(*btSlice)
|
||||||
slice.m.Lock()
|
slice.m.Lock()
|
||||||
for _, b := range slice.data {
|
for _, b := range slice.data {
|
||||||
if b.Path == path {
|
if b.Path == path && b.BoxID == boxID {
|
||||||
ids = append(ids, b.RootID)
|
ids = append(ids, b.RootID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -386,8 +386,15 @@ func IndexBlockTree(tree *parse.Tree) {
|
|||||||
}
|
}
|
||||||
slice := val.(*btSlice)
|
slice := val.(*btSlice)
|
||||||
slice.m.Lock()
|
slice.m.Lock()
|
||||||
|
if bt := slice.data[n.ID]; nil != bt {
|
||||||
|
if bt.Updated != n.IALAttr("updated") {
|
||||||
slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}
|
slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}
|
||||||
slice.changed = time.Now()
|
slice.changed = time.Now()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
slice.data[n.ID] = &BlockTree{ID: n.ID, ParentID: parentID, RootID: tree.ID, BoxID: tree.Box, Path: tree.Path, HPath: tree.HPath, Updated: n.IALAttr("updated"), Type: TypeAbbr(n.Type.String())}
|
||||||
|
slice.changed = time.Now()
|
||||||
|
}
|
||||||
slice.m.Unlock()
|
slice.m.Unlock()
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
@ -401,6 +408,7 @@ func InitBlockTree(force bool) {
|
|||||||
if nil != err {
|
if nil != err {
|
||||||
logging.LogErrorf("remove blocktree file failed: %s", err)
|
logging.LogErrorf("remove blocktree file failed: %s", err)
|
||||||
}
|
}
|
||||||
|
blockTrees = &sync.Map{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -485,7 +493,7 @@ func SaveBlockTree(force bool) {
|
|||||||
|
|
||||||
key := arg.(map[string]interface{})["key"].(string)
|
key := arg.(map[string]interface{})["key"].(string)
|
||||||
slice := arg.(map[string]interface{})["value"].(*btSlice)
|
slice := arg.(map[string]interface{})["value"].(*btSlice)
|
||||||
if !force && (slice.changed.IsZero() || slice.changed.After(start.Add(-7*time.Second))) {
|
if !force && slice.changed.IsZero() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -508,16 +516,22 @@ func SaveBlockTree(force bool) {
|
|||||||
size += uint64(len(data))
|
size += uint64(len(data))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var count int
|
||||||
blockTrees.Range(func(key, value interface{}) bool {
|
blockTrees.Range(func(key, value interface{}) bool {
|
||||||
slice := value.(*btSlice)
|
slice := value.(*btSlice)
|
||||||
if !force && (slice.changed.IsZero() || slice.changed.After(start.Add(-7*time.Second))) {
|
if !force && slice.changed.IsZero() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
count++
|
||||||
|
|
||||||
waitGroup.Add(1)
|
waitGroup.Add(1)
|
||||||
p.Invoke(map[string]interface{}{"key": key, "value": value})
|
p.Invoke(map[string]interface{}{"key": key, "value": value})
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
if 0 < count {
|
||||||
|
logging.LogInfof("wrote block trees [%d]", count)
|
||||||
|
}
|
||||||
|
|
||||||
waitGroup.Wait()
|
waitGroup.Wait()
|
||||||
p.Release()
|
p.Release()
|
||||||
|
Loading…
Reference in New Issue
Block a user