From d2c0c26252876a4b7b302dc3f03f0e82130b210a Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Fri, 15 Dec 2023 08:56:44 +0800 Subject: [PATCH] :art: Delete the corresponding data in the database attributes table after deleting the doc https://github.com/siyuan-note/siyuan/issues/9875 --- kernel/sql/database.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/sql/database.go b/kernel/sql/database.go index 935678d87..17ef87d43 100644 --- a/kernel/sql/database.go +++ b/kernel/sql/database.go @@ -1122,6 +1122,10 @@ func deleteByRootID(tx *sql.Tx, rootID string, context map[string]interface{}) ( if err = execStmtTx(tx, stmt, rootID); nil != err { return } + stmt = "DELETE FROM attributes WHERE root_id = ?" + if err = execStmtTx(tx, stmt, rootID); nil != err { + return + } ClearCache() eventbus.Publish(eventbus.EvtSQLDeleteBlocks, context, rootID) return @@ -1160,6 +1164,10 @@ func batchDeleteByRootIDs(tx *sql.Tx, rootIDs []string, context map[string]inter if err = execStmtTx(tx, stmt); nil != err { return } + stmt = "DELETE FROM attributes WHERE root_id IN " + ids + if err = execStmtTx(tx, stmt); nil != err { + return + } ClearCache() eventbus.Publish(eventbus.EvtSQLDeleteBlocks, context, fmt.Sprintf("%d", len(rootIDs))) return @@ -1196,6 +1204,10 @@ func batchDeleteByPathPrefix(tx *sql.Tx, boxID, pathPrefix string) (err error) { if err = execStmtTx(tx, stmt, boxID, pathPrefix+"%"); nil != err { return } + stmt = "DELETE FROM attributes WHERE box = ? AND path LIKE ?" + if err = execStmtTx(tx, stmt, boxID, pathPrefix+"%"); nil != err { + return + } ClearCache() return }