mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-04 01:40:46 +08:00
This commit is contained in:
parent
bc7b29bd0e
commit
bd153b89c5
@ -419,7 +419,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sql.DeleteAssetsByHashes(hashes)
|
sql.BatchRemoveAssetsQueue(hashes)
|
||||||
|
|
||||||
for _, unusedAsset := range unusedAssets {
|
for _, unusedAsset := range unusedAssets {
|
||||||
if unusedAsset = filepath.Join(util.DataDir, unusedAsset); gulu.File.IsExist(unusedAsset) {
|
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)
|
hash, _ := util.GetEtag(absPath)
|
||||||
sql.DeleteAssetsByHashes([]string{hash})
|
sql.BatchRemoveAssetsQueue([]string{hash})
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = os.RemoveAll(absPath); nil != err {
|
if err = os.RemoveAll(absPath); nil != err {
|
||||||
|
@ -92,15 +92,11 @@ func docTitleImgAsset(root *ast.Node) *Asset {
|
|||||||
return nil
|
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 = ''"
|
sqlStmt := "DELETE FROM assets WHERE hash IN ('" + strings.Join(hashes, "','") + "') OR hash = ''"
|
||||||
tx, err := beginTx()
|
err = execStmtTx(tx, sqlStmt)
|
||||||
if nil != err {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
execStmtTx(tx, sqlStmt)
|
|
||||||
commitTx(tx)
|
|
||||||
}
|
|
||||||
|
|
||||||
func QueryAssetByHash(hash string) (ret *Asset) {
|
func QueryAssetByHash(hash string) (ret *Asset) {
|
||||||
sqlStmt := "SELECT * FROM assets WHERE hash = ?"
|
sqlStmt := "SELECT * FROM assets WHERE hash = ?"
|
||||||
|
@ -41,7 +41,7 @@ var (
|
|||||||
|
|
||||||
type dbQueueOperation struct {
|
type dbQueueOperation struct {
|
||||||
inQueueTime time.Time
|
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_assets
|
||||||
|
|
||||||
indexPath string // index
|
indexPath string // index
|
||||||
upsertTree *parse.Tree // upsert/insert_refs
|
upsertTree *parse.Tree // upsert/insert_refs
|
||||||
@ -52,6 +52,7 @@ type dbQueueOperation struct {
|
|||||||
renameTree *parse.Tree // rename
|
renameTree *parse.Tree // rename
|
||||||
renameTreeOldHPath string // rename
|
renameTreeOldHPath string // rename
|
||||||
block *Block // update_block_content
|
block *Block // update_block_content
|
||||||
|
removeAssetHashes []string // delete_assets
|
||||||
}
|
}
|
||||||
|
|
||||||
func FlushTxJob() {
|
func FlushTxJob() {
|
||||||
@ -169,6 +170,8 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
|
|||||||
err = upsertRefs(tx, op.upsertTree)
|
err = upsertRefs(tx, op.upsertTree)
|
||||||
case "update_block_content":
|
case "update_block_content":
|
||||||
err = updateBlockContent(tx, op.block)
|
err = updateBlockContent(tx, op.block)
|
||||||
|
case "delete_assets":
|
||||||
|
err = deleteAssetsByHashes(tx, op.removeAssetHashes)
|
||||||
default:
|
default:
|
||||||
msg := fmt.Sprintf("unknown operation [%s]", op.action)
|
msg := fmt.Sprintf("unknown operation [%s]", op.action)
|
||||||
logging.LogErrorf(msg)
|
logging.LogErrorf(msg)
|
||||||
@ -177,6 +180,14 @@ func execOp(op *dbQueueOperation, tx *sql.Tx, context map[string]interface{}) (e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
func UpdateBlockContentQueue(block *Block) {
|
||||||
dbQueueLock.Lock()
|
dbQueueLock.Lock()
|
||||||
defer dbQueueLock.Unlock()
|
defer dbQueueLock.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user