mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 23:20:13 +01:00
🎨 Improve dynamic anchor text auto-refresh stability https://github.com/siyuan-note/siyuan/issues/8234
This commit is contained in:
parent
c74f1ce0d9
commit
0e136eed52
1 changed files with 18 additions and 10 deletions
|
|
@ -22,6 +22,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime/debug"
|
"runtime/debug"
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
@ -1135,7 +1136,8 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 收集引用的定义块 ID
|
// 收集引用的定义块 ID
|
||||||
refDefIDs := getRefDefIDs(oldNode)
|
oldDefIDs := getRefDefIDs(oldNode)
|
||||||
|
var newDefIDs []string
|
||||||
|
|
||||||
var unlinks []*ast.Node
|
var unlinks []*ast.Node
|
||||||
ast.Walk(subTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
ast.Walk(subTree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||||
|
|
@ -1160,7 +1162,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
refDefIDs = append(refDefIDs, n.TextMarkBlockRefID)
|
newDefIDs = append(newDefIDs, n.TextMarkBlockRefID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ast.WalkContinue
|
return ast.WalkContinue
|
||||||
|
|
@ -1169,14 +1171,20 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||||
n.Unlink()
|
n.Unlink()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 推送定义节点引用计数
|
oldDefIDs = gulu.Str.RemoveDuplicatedElem(oldDefIDs)
|
||||||
refDefIDs = gulu.Str.RemoveDuplicatedElem(refDefIDs)
|
newDefIDs = gulu.Str.RemoveDuplicatedElem(newDefIDs)
|
||||||
for _, defID := range refDefIDs {
|
refDefIDs := oldDefIDs
|
||||||
defTree, _ := LoadTreeByBlockID(defID)
|
|
||||||
if nil != defTree {
|
if !slices.Equal(oldDefIDs, newDefIDs) { // 如果引用发生了变化,则推送定义节点引用计数
|
||||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
refDefIDs = append(refDefIDs, newDefIDs...)
|
||||||
if nil != defNode {
|
refDefIDs = gulu.Str.RemoveDuplicatedElem(refDefIDs)
|
||||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, 1*time.Second, pushSetDefRefCount, defTree.ID, defNode.ID)
|
for _, defID := range refDefIDs {
|
||||||
|
defTree, _ := LoadTreeByBlockID(defID)
|
||||||
|
if nil != defTree {
|
||||||
|
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||||
|
if nil != defNode {
|
||||||
|
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, 1*time.Second, pushSetDefRefCount, defTree.ID, defNode.ID)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue