mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-25 09:46:10 +01:00
This commit is contained in:
parent
c88268fbfd
commit
3a36def366
9 changed files with 22 additions and 25 deletions
|
|
@ -397,7 +397,7 @@ func (box *Box) moveTrees0(files []*FileInfo) {
|
|||
}
|
||||
|
||||
treenode.SetBlockTreePath(subTree)
|
||||
sql.UpsertTreeQueue(subTree)
|
||||
sql.RenameTreeQueue(subTree)
|
||||
msg := fmt.Sprintf(Conf.Language(107), subTree.HPath)
|
||||
util.PushStatusBar(msg)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -882,11 +882,11 @@ func indexWriteJSONQueueWithoutChangeTime(tree *parse.Tree) (err error) {
|
|||
return writeJSONQueueWithoutChangeTime(tree)
|
||||
}
|
||||
|
||||
func renameWriteJSONQueue(tree *parse.Tree, oldHPath string) (err error) {
|
||||
func renameWriteJSONQueue(tree *parse.Tree) (err error) {
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
return
|
||||
}
|
||||
sql.RenameTreeQueue(tree, oldHPath)
|
||||
sql.RenameTreeQueue(tree)
|
||||
treenode.IndexBlockTree(tree)
|
||||
return
|
||||
}
|
||||
|
|
@ -1288,12 +1288,10 @@ func RenameDoc(boxID, p, title string) (err error) {
|
|||
}
|
||||
title = strings.ReplaceAll(title, "/", "")
|
||||
|
||||
oldHPath := tree.HPath
|
||||
tree.HPath = path.Join(path.Dir(tree.HPath), title)
|
||||
tree.Root.SetIALAttr("title", title)
|
||||
tree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
|
||||
if err = renameWriteJSONQueue(tree, oldHPath); nil != err {
|
||||
if err = renameWriteJSONQueue(tree); nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1097,18 +1097,18 @@ func batchDeleteByPathPrefix(tx *sql.Tx, boxID, pathPrefix string) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func batchUpdateHPath(tx *sql.Tx, boxID, rootID, oldHPath, newHPath string) (err error) {
|
||||
stmt := "UPDATE blocks SET hpath = ? WHERE box = ? AND root_id = ? AND hpath = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID, oldHPath); nil != err {
|
||||
func batchUpdateHPath(tx *sql.Tx, boxID, rootID, newHPath string) (err error) {
|
||||
stmt := "UPDATE blocks SET hpath = ? WHERE box = ? AND root_id = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID); nil != err {
|
||||
return
|
||||
}
|
||||
stmt = "UPDATE blocks_fts SET hpath = ? WHERE box = ? AND root_id = ? AND hpath = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID, oldHPath); nil != err {
|
||||
stmt = "UPDATE blocks_fts SET hpath = ? WHERE box = ? AND root_id = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID); nil != err {
|
||||
return
|
||||
}
|
||||
if !caseSensitive {
|
||||
stmt = "UPDATE blocks_fts_case_insensitive SET hpath = ? WHERE box = ? AND root_id = ? AND hpath = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID, oldHPath); nil != err {
|
||||
stmt = "UPDATE blocks_fts_case_insensitive SET hpath = ? WHERE box = ? AND root_id = ?"
|
||||
if err = execStmtTx(tx, stmt, newHPath, boxID, rootID); nil != err {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,6 @@ type dbQueueOperation struct {
|
|||
removeTreeIDs []string // delete_ids
|
||||
box string // delete_box/delete_box_refs/index
|
||||
renameTree *parse.Tree // rename
|
||||
renameTreeOldHPath string // rename
|
||||
block *Block // update_block_content
|
||||
removeAssetHashes []string // delete_assets
|
||||
}
|
||||
|
|
@ -168,7 +167,7 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
|
|||
case "delete_ids":
|
||||
err = batchDeleteByRootIDs(tx, op.removeTreeIDs, context)
|
||||
case "rename":
|
||||
err = batchUpdateHPath(tx, op.renameTree.Box, op.renameTree.ID, op.renameTreeOldHPath, op.renameTree.HPath)
|
||||
err = batchUpdateHPath(tx, op.renameTree.Box, op.renameTree.ID, op.renameTree.HPath)
|
||||
if nil != err {
|
||||
break
|
||||
}
|
||||
|
|
@ -303,15 +302,15 @@ func UpsertTreeQueue(tree *parse.Tree) {
|
|||
operationQueue = append(operationQueue, newOp)
|
||||
}
|
||||
|
||||
func RenameTreeQueue(tree *parse.Tree, oldHPath string) {
|
||||
func RenameTreeQueue(tree *parse.Tree) {
|
||||
dbQueueLock.Lock()
|
||||
defer dbQueueLock.Unlock()
|
||||
|
||||
newOp := &dbQueueOperation{
|
||||
renameTree: tree,
|
||||
renameTreeOldHPath: oldHPath,
|
||||
inQueueTime: time.Now(),
|
||||
action: "rename"}
|
||||
renameTree: tree,
|
||||
inQueueTime: time.Now(),
|
||||
action: "rename",
|
||||
}
|
||||
for i, op := range operationQueue {
|
||||
if "rename" == op.action && op.renameTree.ID == tree.ID { // 相同树则覆盖
|
||||
operationQueue[i] = newOp
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue