🎨 Automatically refresh database views after deleting/rolling back documents https://github.com/siyuan-note/siyuan/issues/12081
This commit is contained in:
parent
4ccf648e57
commit
8fee81c8c1
3 changed files with 32 additions and 15 deletions
|
@ -1671,8 +1671,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
continue
|
||||
}
|
||||
|
||||
syncDelete2AttributeView(removeTree.Root)
|
||||
syncDelete2Block(removeTree.Root)
|
||||
syncDelete2AvBlock(removeTree.Root)
|
||||
}
|
||||
|
||||
if existChildren {
|
||||
|
|
|
@ -248,6 +248,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
var avIDs []string
|
||||
tree, _ := loadTree(srcPath, util.NewLute())
|
||||
if nil != tree {
|
||||
historyDir := strings.TrimPrefix(historyPath, util.HistoryDir+string(os.PathSeparator))
|
||||
|
@ -266,8 +267,11 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
logging.LogErrorf("copy av [%s] failed: %s", srcAvPath, copyErr)
|
||||
}
|
||||
}
|
||||
|
||||
avIDs = append(avIDs, avNode.AttributeViewID)
|
||||
}
|
||||
}
|
||||
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||
|
||||
tree.Box = boxID
|
||||
tree.Path = filepath.ToSlash(strings.TrimPrefix(destPath, util.DataDir+string(os.PathSeparator)+boxID))
|
||||
|
@ -305,6 +309,11 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
"refText": refText,
|
||||
}
|
||||
util.PushEvent(evt)
|
||||
|
||||
// 刷新属性视图
|
||||
for _, avID := range avIDs {
|
||||
util.PushReloadAttrView(avID)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -799,14 +799,26 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
if needSyncDel2AvBlock {
|
||||
syncDelete2AttributeView(node)
|
||||
syncDelete2Block(node)
|
||||
syncDelete2AvBlock(node)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func syncDelete2Block(node *ast.Node) {
|
||||
var changedAvIDs []string
|
||||
func syncDelete2AvBlock(node *ast.Node) {
|
||||
changedAvIDs := syncDelete2AttributeView(node)
|
||||
avIDs := syncDelete2Block(node)
|
||||
changedAvIDs = append(changedAvIDs, avIDs...)
|
||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||
|
||||
go func() {
|
||||
time.Sleep(256 * time.Millisecond)
|
||||
for _, avID := range changedAvIDs {
|
||||
util.PushReloadAttrView(avID)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func syncDelete2Block(node *ast.Node) (changedAvIDs []string) {
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || ast.NodeAttributeView != n.Type {
|
||||
return ast.WalkContinue
|
||||
|
@ -850,14 +862,12 @@ func syncDelete2Block(node *ast.Node) {
|
|||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||
for _, avID := range changedAvIDs {
|
||||
util.PushReloadAttrView(avID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func syncDelete2AttributeView(node *ast.Node) {
|
||||
changedAvIDs := hashset.New()
|
||||
func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
if !entering || !n.IsBlock() {
|
||||
return ast.WalkContinue
|
||||
|
@ -891,15 +901,14 @@ func syncDelete2AttributeView(node *ast.Node) {
|
|||
|
||||
if changedAv {
|
||||
av.SaveAttributeView(attrView)
|
||||
changedAvIDs.Add(avID)
|
||||
changedAvIDs = append(changedAvIDs, avID)
|
||||
}
|
||||
}
|
||||
return ast.WalkContinue
|
||||
})
|
||||
|
||||
for _, avID := range changedAvIDs.Values() {
|
||||
util.PushReloadAttrView(avID.(string))
|
||||
}
|
||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||
|
|
Loading…
Add table
Reference in a new issue