mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🐛 Subdocument path not updated after moving parent document https://github.com/siyuan-note/siyuan/issues/12493
This commit is contained in:
parent
22ffd923d3
commit
c67ff98972
2 changed files with 31 additions and 10 deletions
|
|
@ -1251,23 +1251,44 @@ func batchDeleteByPathPrefix(tx *sql.Tx, boxID, pathPrefix string) (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func batchUpdateHPath(tx *sql.Tx, rootID, newHPath string, context map[string]interface{}) (err error) {
|
func batchUpdatePath(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||||
stmt := "UPDATE blocks SET hpath = ? WHERE root_id = ?"
|
stmt := "UPDATE blocks SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
|
||||||
if err = execStmtTx(tx, stmt, newHPath, rootID); err != nil {
|
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.HPath, tree.ID); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stmt = "UPDATE blocks_fts SET hpath = ? WHERE root_id = ?"
|
stmt = "UPDATE blocks_fts SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
|
||||||
if err = execStmtTx(tx, stmt, newHPath, rootID); err != nil {
|
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.HPath, tree.ID); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
stmt = "UPDATE blocks_fts_case_insensitive SET hpath = ? WHERE root_id = ?"
|
stmt = "UPDATE blocks_fts_case_insensitive SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
|
||||||
if err = execStmtTx(tx, stmt, newHPath, rootID); err != nil {
|
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.HPath, tree.ID); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClearCache()
|
ClearCache()
|
||||||
evtHash := fmt.Sprintf("%x", sha256.Sum256([]byte(rootID)))[:7]
|
evtHash := fmt.Sprintf("%x", sha256.Sum256([]byte(tree.ID)))[:7]
|
||||||
|
eventbus.Publish(eventbus.EvtSQLUpdateBlocksHPaths, context, 1, evtHash)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func batchUpdateHPath(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
|
||||||
|
stmt := "UPDATE blocks SET hpath = ? WHERE root_id = ?"
|
||||||
|
if err = execStmtTx(tx, stmt, tree.HPath, tree.ID); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
stmt = "UPDATE blocks_fts SET hpath = ? WHERE root_id = ?"
|
||||||
|
if err = execStmtTx(tx, stmt, tree.HPath, tree.ID); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !caseSensitive {
|
||||||
|
stmt = "UPDATE blocks_fts_case_insensitive SET hpath = ? WHERE root_id = ?"
|
||||||
|
if err = execStmtTx(tx, stmt, tree.HPath, tree.ID); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ClearCache()
|
||||||
|
evtHash := fmt.Sprintf("%x", sha256.Sum256([]byte(tree.ID)))[:7]
|
||||||
eventbus.Publish(eventbus.EvtSQLUpdateBlocksHPaths, context, 1, evtHash)
|
eventbus.Publish(eventbus.EvtSQLUpdateBlocksHPaths, context, 1, evtHash)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -187,13 +187,13 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
|
||||||
case "delete_ids":
|
case "delete_ids":
|
||||||
err = batchDeleteByRootIDs(tx, op.removeTreeIDs, context)
|
err = batchDeleteByRootIDs(tx, op.removeTreeIDs, context)
|
||||||
case "rename":
|
case "rename":
|
||||||
err = batchUpdateHPath(tx, op.renameTree.ID, op.renameTree.HPath, context)
|
err = batchUpdateHPath(tx, op.renameTree, context)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
err = updateRootContent(tx, path.Base(op.renameTree.HPath), op.renameTree.Root.IALAttr("updated"), op.renameTree.ID)
|
err = updateRootContent(tx, path.Base(op.renameTree.HPath), op.renameTree.Root.IALAttr("updated"), op.renameTree.ID)
|
||||||
case "rename_sub_tree":
|
case "rename_sub_tree":
|
||||||
err = batchUpdateHPath(tx, op.renameTree.ID, op.renameTree.HPath, context)
|
err = batchUpdatePath(tx, op.renameTree, context)
|
||||||
case "delete_box":
|
case "delete_box":
|
||||||
err = deleteByBoxTx(tx, op.box)
|
err = deleteByBoxTx(tx, op.box)
|
||||||
case "delete_box_refs":
|
case "delete_box_refs":
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue