🎨 Reindex only the current document after rolling back the document https://github.com/siyuan-note/siyuan/issues/12320

This commit is contained in:
Daniel 2024-08-29 11:44:47 +08:00
parent 0ac17d30f7
commit 9f1906c003
No known key found for this signature in database
GPG Key ID: 86211BA83DF03017

View File

@ -228,7 +228,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
WaitForWritingFiles() WaitForWritingFiles()
srcPath := historyPath srcPath := historyPath
var destPath string var destPath, parentHPath string
baseName := filepath.Base(historyPath) baseName := filepath.Base(historyPath)
id := strings.TrimSuffix(baseName, ".sy") id := strings.TrimSuffix(baseName, ".sy")
@ -239,7 +239,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
} }
} }
destPath, err = getRollbackDockPath(boxID, historyPath) destPath, parentHPath, err = getRollbackDockPath(boxID, historyPath)
if nil != err { if nil != err {
return return
} }
@ -269,7 +269,19 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
} }
} }
FullReindex() tree.Box = boxID
tree.Path = filepath.ToSlash(strings.TrimPrefix(destPath, util.DataDir+string(os.PathSeparator)+boxID))
tree.HPath = parentHPath + "/" + tree.Root.IALAttr("title")
// 仅重新索引该文档,不进行全量索引
// Reindex only the current document after rolling back the document https://github.com/siyuan-note/siyuan/issues/12320
treenode.RemoveBlockTree(id)
treenode.IndexBlockTree(tree)
sql.RemoveTreeQueue(id)
sql.IndexTreeQueue(tree)
util.PushReloadFiletree()
util.PushMsg(Conf.Language(102), 3000)
IncSync() IncSync()
go func() { go func() {
sql.WaitForWritingDatabase() sql.WaitForWritingDatabase()
@ -297,7 +309,7 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
return nil return nil
} }
func getRollbackDockPath(boxID, historyPath string) (destPath string, err error) { func getRollbackDockPath(boxID, historyPath string) (destPath, parentHPath string, err error) {
baseName := filepath.Base(historyPath) baseName := filepath.Base(historyPath)
parentID := strings.TrimSuffix(filepath.Base(filepath.Dir(historyPath)), ".sy") parentID := strings.TrimSuffix(filepath.Base(filepath.Dir(historyPath)), ".sy")
parentWorkingDoc := treenode.GetBlockTree(parentID) parentWorkingDoc := treenode.GetBlockTree(parentID)
@ -309,6 +321,7 @@ func getRollbackDockPath(boxID, historyPath string) (destPath string, err error)
return return
} }
destPath = filepath.Join(parentDir, baseName) destPath = filepath.Join(parentDir, baseName)
parentHPath = parentWorkingDoc.HPath
} else { } else {
// 父路径如果不是文档,则恢复到笔记本根路径下 // 父路径如果不是文档,则恢复到笔记本根路径下
destPath = filepath.Join(util.DataDir, boxID, baseName) destPath = filepath.Join(util.DataDir, boxID, baseName)