Skip to content

Commit

Permalink
🎨 Automatically refresh reference counts after deleting or rolling ba…
Browse files Browse the repository at this point in the history
…ck a document #12682
  • Loading branch information
88250 committed Oct 3, 2024
1 parent 169e6a5 commit 82b89af
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
21 changes: 17 additions & 4 deletions kernel/model/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -1742,13 +1742,26 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
util.PushEvent(evt)

refreshParentDocInfo(tree)
task.AppendTask(task.DatabaseIndex, removeDoc0, box, p, childrenDir)
task.AppendTask(task.DatabaseIndex, removeDoc0, tree, childrenDir)
}

func removeDoc0(box *Box, p, childrenDir string) {
func removeDoc0(tree *parse.Tree, childrenDir string) {
// 收集引用的定义块 ID
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, 1*time.Second, refreshRefCount, defTree.ID, defNode.ID)
}
}
}

treenode.RemoveBlockTreesByPathPrefix(childrenDir)
sql.RemoveTreePathQueue(box.ID, childrenDir)
cache.RemoveDocIAL(p)
sql.RemoveTreePathQueue(tree.Box, childrenDir)
cache.RemoveDocIAL(tree.Path)
return
}

Expand Down
13 changes: 13 additions & 0 deletions kernel/model/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,19 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
"refText": refText,
}
util.PushEvent(evt)

// 收集引用的定义块 ID
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, 1*time.Second, refreshRefCount, defTree.ID, defNode.ID)
}
}
}
}()
return nil
}
Expand Down

0 comments on commit 82b89af

Please sign in to comment.