An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 改进清理未引用资源 https://github.com/siyuan-note/siyuan/issues/7216
Liang Dingbd153b89c534
diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex bb07f0b7a7..add83cead1 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -419,7 +419,7 @@ func RemoveUnusedAssets() (ret []string) {}}- sql.DeleteAssetsByHashes(hashes)+ sql.BatchRemoveAssetsQueue(hashes)for _, unusedAsset := range unusedAssets {if unusedAsset = filepath.Join(util.DataDir, unusedAsset); gulu.File.IsExist(unusedAsset) {@@ -458,7 +458,7 @@ func RemoveUnusedAsset(p string) (ret string) {}hash, _ := util.GetEtag(absPath)- sql.DeleteAssetsByHashes([]string{hash})+ sql.BatchRemoveAssetsQueue([]string{hash})}if err = os.RemoveAll(absPath); nil != err {diff --git a/kernel/sql/asset.go b/kernel/sql/asset.goindex b5abebbf91..072829d09d 100644--- a/kernel/sql/asset.go+++ b/kernel/sql/asset.go@@ -92,14 +92,10 @@ func docTitleImgAsset(root *ast.Node) *Asset {return nil}-func DeleteAssetsByHashes(hashes []string) {+func deleteAssetsByHashes(tx *sql.Tx, hashes []string) (err error) {sqlStmt := "DELETE FROM assets WHERE hash IN ('" + strings.Join(hashes, "','") + "') OR hash = ''"- tx, err := beginTx()- if nil != err {- return- }- execStmtTx(tx, sqlStmt)- commitTx(tx)+ err = execStmtTx(tx, sqlStmt)+ return}func QueryAssetByHash(hash string) (ret *Asset) {diff --git a/kernel/sql/queue.go b/kernel/sql/queue.goindex 6a9b22c1d6..6026007d41 100644--- a/kernel/sql/queue.go+++ b/kernel/sql/queue.go@@ -41,7 +41,7 @@ var (type dbQueueOperation struct {inQueueTime time.Time- action string // upsert/delete/delete_id/rename/delete_box/delete_box_refs/insert_refs/index/delete_ids/update_block_content+ action string // upsert/delete/delete_id/rename/delete_box/delete_box_refs/insert_refs/index/delete_ids/update_block_content/delete_assetsindexPath string // indexupsertTree *parse.Tree // upsert/insert_refs@@ -52,6 +52,7 @@ type dbQueueOperation struct {renameTree *parse.Tree // renamerenameTreeOldHPath string // renameblock *Block // update_block_content+ removeAssetHashes []string // delete_assets}func FlushTxJob() {@@ -169,6 +170,8 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (eerr = upsertRefs(tx, op.upsertTree)case "update_block_content":err = updateBlockContent(tx, op.block)+ case "delete_assets":+ err = deleteAssetsByHashes(tx, op.removeAssetHashes)default:msg := fmt.Sprintf("unknown operation [%s]", op.action)logging.LogErrorf(msg)@@ -177,6 +180,14 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (ereturn}+func BatchRemoveAssetsQueue(hashes []string) {+ dbQueueLock.Lock()+ defer dbQueueLock.Unlock()++ newOp := &dbQueueOperation{removeAssetHashes: hashes, inQueueTime: time.Now(), action: "delete_assets"}+ operationQueue = append(operationQueue, newOp)+}+func UpdateBlockContentQueue(block *Block) {dbQueueLock.Lock()defer dbQueueLock.Unlock()@@ -336,4 +347,4 @@ func mergeUpsertTrees() (ops []*dbQueueOperation) {ops = operationQueueoperationQueue = nilreturn-}\ No newline at end of file+}