mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
🎨 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
syncDelete2AttributeView(removeTree.Root)
|
syncDelete2AvBlock(removeTree.Root)
|
||||||
syncDelete2Block(removeTree.Root)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if existChildren {
|
if existChildren {
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var avIDs []string
|
||||||
tree, _ := loadTree(srcPath, util.NewLute())
|
tree, _ := loadTree(srcPath, util.NewLute())
|
||||||
if nil != tree {
|
if nil != tree {
|
||||||
historyDir := strings.TrimPrefix(historyPath, util.HistoryDir+string(os.PathSeparator))
|
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)
|
logging.LogErrorf("copy av [%s] failed: %s", srcAvPath, copyErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
avIDs = append(avIDs, avNode.AttributeViewID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
avIDs = gulu.Str.RemoveDuplicatedElem(avIDs)
|
||||||
|
|
||||||
tree.Box = boxID
|
tree.Box = boxID
|
||||||
tree.Path = filepath.ToSlash(strings.TrimPrefix(destPath, util.DataDir+string(os.PathSeparator)+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,
|
"refText": refText,
|
||||||
}
|
}
|
||||||
util.PushEvent(evt)
|
util.PushEvent(evt)
|
||||||
|
|
||||||
|
// 刷新属性视图
|
||||||
|
for _, avID := range avIDs {
|
||||||
|
util.PushReloadAttrView(avID)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -799,14 +799,26 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if needSyncDel2AvBlock {
|
if needSyncDel2AvBlock {
|
||||||
syncDelete2AttributeView(node)
|
syncDelete2AvBlock(node)
|
||||||
syncDelete2Block(node)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncDelete2Block(node *ast.Node) {
|
func syncDelete2AvBlock(node *ast.Node) {
|
||||||
var changedAvIDs []string
|
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 {
|
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || ast.NodeAttributeView != n.Type {
|
if !entering || ast.NodeAttributeView != n.Type {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
@ -850,14 +862,12 @@ func syncDelete2Block(node *ast.Node) {
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
|
||||||
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||||
for _, avID := range changedAvIDs {
|
return
|
||||||
util.PushReloadAttrView(avID)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func syncDelete2AttributeView(node *ast.Node) {
|
func syncDelete2AttributeView(node *ast.Node) (changedAvIDs []string) {
|
||||||
changedAvIDs := hashset.New()
|
|
||||||
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(node, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
if !entering || !n.IsBlock() {
|
if !entering || !n.IsBlock() {
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
@ -891,15 +901,14 @@ func syncDelete2AttributeView(node *ast.Node) {
|
||||||
|
|
||||||
if changedAv {
|
if changedAv {
|
||||||
av.SaveAttributeView(attrView)
|
av.SaveAttributeView(attrView)
|
||||||
changedAvIDs.Add(avID)
|
changedAvIDs = append(changedAvIDs, avID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
})
|
})
|
||||||
|
|
||||||
for _, avID := range changedAvIDs.Values() {
|
changedAvIDs = gulu.Str.RemoveDuplicatedElem(changedAvIDs)
|
||||||
util.PushReloadAttrView(avID.(string))
|
return
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue