mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-16 14:40:12 +01:00
🎨 Improve reference count update after document convert to heading https://github.com/siyuan-note/siyuan/issues/15299
This commit is contained in:
parent
ef0a278334
commit
62d560e7a8
8 changed files with 28 additions and 57 deletions
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/task"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -43,14 +44,20 @@ func RefreshBacklink(id string) {
|
|||
}
|
||||
|
||||
func refreshRefsByDefID(defID string) {
|
||||
refs := sql.QueryRefsByDefID(defID, false)
|
||||
refs := sql.QueryRefsByDefID(defID, true)
|
||||
var rootIDs []string
|
||||
for _, ref := range refs {
|
||||
rootIDs = append(rootIDs, ref.RootID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, ref.DefBlockID)
|
||||
}
|
||||
rootIDs = gulu.Str.RemoveDuplicatedElem(rootIDs)
|
||||
trees := filesys.LoadTrees(rootIDs)
|
||||
for _, tree := range trees {
|
||||
sql.UpdateRefsTreeQueue(tree)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, tree.ID)
|
||||
}
|
||||
if bt := treenode.GetBlockTree(defID); nil != bt {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1599,13 +1599,7 @@ func removeDoc0(tree *parse.Tree, childrenDir string) {
|
|||
refDefIDs := getRefDefIDs(tree.Root)
|
||||
// 推送定义节点引用计数
|
||||
for _, defID := range refDefIDs {
|
||||
defTree, _ := LoadTreeByBlockID(defID)
|
||||
if nil != defTree {
|
||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||
if nil != defNode {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defTree.ID, defNode.ID)
|
||||
}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
|
||||
treenode.RemoveBlockTreesByPathPrefix(childrenDir)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
|
|
@ -273,10 +274,10 @@ func Doc2Heading(srcID, targetID string, after bool) (srcTreeBox, srcTreePath st
|
|||
treenode.RemoveBlockTreesByRootID(targetTree.ID)
|
||||
err = indexWriteTreeUpsertQueue(targetTree)
|
||||
IncSync()
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(targetTree.ID)
|
||||
go func() {
|
||||
sql.FlushQueue()
|
||||
time.Sleep(util.SQLFlushInterval)
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(targetTree.ID)
|
||||
ResetVirtualBlockRefCache()
|
||||
}()
|
||||
return
|
||||
|
|
@ -413,10 +414,9 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath, previousPath string) (sr
|
|||
return "", "", err
|
||||
}
|
||||
IncSync()
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(newTree.ID)
|
||||
go func() {
|
||||
sql.FlushQueue()
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(newTree.ID)
|
||||
ResetVirtualBlockRefCache()
|
||||
}()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -355,13 +355,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
refDefIDs := getRefDefIDs(tree.Root)
|
||||
// 推送定义节点引用计数
|
||||
for _, defID := range refDefIDs {
|
||||
defTree, _ := LoadTreeByBlockID(defID)
|
||||
if nil != defTree {
|
||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||
if nil != defNode {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defTree.ID, defNode.ID)
|
||||
}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -138,10 +138,9 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath, previousPath string) (
|
|||
return "", "", err
|
||||
}
|
||||
IncSync()
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(newTree.ID)
|
||||
go func() {
|
||||
sql.FlushQueue()
|
||||
RefreshBacklink(srcTree.ID)
|
||||
RefreshBacklink(newTree.ID)
|
||||
ResetVirtualBlockRefCache()
|
||||
}()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ func ReloadProtyle(rootID string) {
|
|||
}
|
||||
|
||||
// refreshRefCount 用于刷新定义块处的引用计数。
|
||||
func refreshRefCount(rootID, blockID string) {
|
||||
func refreshRefCount(blockID string) {
|
||||
sql.FlushQueue()
|
||||
|
||||
bt := treenode.GetBlockTree(blockID)
|
||||
|
|
@ -177,7 +177,7 @@ func refreshRefCount(rootID, blockID string) {
|
|||
defIDs = append(defIDs, bt.ID)
|
||||
}
|
||||
|
||||
util.PushSetDefRefCount(rootID, blockID, defIDs, refCount, rootRefCount)
|
||||
util.PushSetDefRefCount(bt.RootID, blockID, defIDs, refCount, rootRefCount)
|
||||
}
|
||||
|
||||
// refreshDynamicRefText 用于刷新块引用的动态锚文本。
|
||||
|
|
|
|||
|
|
@ -992,12 +992,7 @@ func replaceNodeTextMarkTextContent(n *ast.Node, method int, keyword, escapedKey
|
|||
for rNode := tree.Root.FirstChild.FirstChild; nil != rNode; rNode = rNode.Next {
|
||||
replaceNodes = append(replaceNodes, rNode)
|
||||
if blockRefID, _, _ := treenode.GetBlockRef(rNode); "" != blockRefID {
|
||||
bt := treenode.GetBlockTree(blockRefID)
|
||||
if nil == bt {
|
||||
continue
|
||||
}
|
||||
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, bt.RootID, blockRefID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, blockRefID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -411,8 +411,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
if err = tx.writeTree(targetTree); err != nil {
|
||||
return
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcTree.ID, srcTree.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, targetTree.ID, srcNode.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcTree.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcNode.ID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -496,8 +496,8 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
if err = tx.writeTree(targetTree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcTree.ID, srcTree.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, targetTree.ID, srcNode.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcTree.ID)
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, srcNode.ID)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -805,13 +805,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
refDefIDs := getRefDefIDs(node)
|
||||
// 推送定义节点引用计数
|
||||
for _, defID := range refDefIDs {
|
||||
defTree, _ := LoadTreeByBlockID(defID)
|
||||
if nil != defTree {
|
||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||
if nil != defNode {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defTree.ID, defNode.ID)
|
||||
}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
|
||||
parent := node.Parent
|
||||
|
|
@ -1136,13 +1130,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
refDefIDs := getRefDefIDs(insertedNode)
|
||||
// 推送定义节点引用计数
|
||||
for _, defID := range refDefIDs {
|
||||
defTree, _ := LoadTreeByBlockID(defID)
|
||||
if nil != defTree {
|
||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||
if nil != defNode {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defTree.ID, defNode.ID)
|
||||
}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
|
||||
upsertAvBlockRel(insertedNode)
|
||||
|
|
@ -1262,13 +1250,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
refDefIDs = append(refDefIDs, newDefIDs...)
|
||||
refDefIDs = gulu.Str.RemoveDuplicatedElem(refDefIDs)
|
||||
for _, defID := range refDefIDs {
|
||||
defTree, _ := LoadTreeByBlockID(defID)
|
||||
if nil != defTree {
|
||||
defNode := treenode.GetNodeInTree(defTree, defID)
|
||||
if nil != defNode {
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defTree.ID, defNode.ID)
|
||||
}
|
||||
}
|
||||
task.AppendAsyncTaskWithDelay(task.SetDefRefCount, util.SQLFlushInterval, refreshRefCount, defID)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue