🐛 Subdocument path not updated after moving parent document https://github.com/siyuan-note/siyuan/issues/12493

This commit is contained in:
Daniel 2024-09-16 11:09:09 +08:00
parent 22ffd923d3
commit c67ff98972
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 31 additions and 10 deletions

View file

@ -1251,23 +1251,44 @@ func batchDeleteByPathPrefix(tx *sql.Tx, boxID, pathPrefix string) (err error) {
return
}
func batchUpdateHPath(tx *sql.Tx, rootID, newHPath string, context map[string]interface{}) (err error) {
stmt := "UPDATE blocks SET hpath = ? WHERE root_id = ?"
if err = execStmtTx(tx, stmt, newHPath, rootID); err != nil {
func batchUpdatePath(tx *sql.Tx, tree *parse.Tree, context map[string]interface{}) (err error) {
stmt := "UPDATE blocks SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.HPath, tree.ID); err != nil {
return
}
stmt = "UPDATE blocks_fts SET hpath = ? WHERE root_id = ?"
if err = execStmtTx(tx, stmt, newHPath, rootID); err != nil {
stmt = "UPDATE blocks_fts SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, 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, newHPath, rootID); err != nil {
stmt = "UPDATE blocks_fts_case_insensitive SET box = ?, path = ?, hpath = ? WHERE root_id = ?"
if err = execStmtTx(tx, stmt, tree.Box, tree.Path, tree.HPath, tree.ID); err != nil {
return
}
}
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)
return
}