An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: 删除未引用资源后已删除的资源仍能搜索到 Fix https://github.com/siyuan-note/siyuan/issues/6737
Liang Ding862b740e7a1c
diff --git a/kernel/cache/asset.go b/kernel/cache/asset.goindex bf9d2368bb..7c68e11181 100644--- a/kernel/cache/asset.go+++ b/kernel/cache/asset.go@@ -33,9 +33,24 @@ type Asset struct {Updated int64 `json:"updated"`}-var Assets = map[string]*Asset{}+var assetsCache = map[string]*Asset{}var assetsLock = sync.Mutex{}+func GetAssets() (ret map[string]*Asset) {+ assetsLock.Lock()+ defer assetsLock.Unlock()++ ret = assetsCache+ return+}++func RemoveAsset(path string) {+ assetsLock.Lock()+ defer assetsLock.Unlock()++ delete(assetsCache, path)+}+func LoadAssets() {defer logging.Recover()@@ -43,6 +58,7 @@ func LoadAssets() {assetsLock.Lock()defer assetsLock.Unlock()+ assetsCache = map[string]*Asset{}assets := util.GetDataAssetsAbsPath()filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {if nil == info {@@ -60,7 +76,7 @@ func LoadAssets() {hName := util.RemoveID(info.Name())path = "assets" + filepath.ToSlash(strings.TrimPrefix(path, assets))- Assets[path] = &Asset{+ assetsCache[path] = &Asset{HName: hName,Path: path,Updated: info.ModTime().UnixMilli(),diff --git a/kernel/model/assets.go b/kernel/model/assets.goindex d67fed9191..f7c50786e5 100644--- a/kernel/model/assets.go+++ b/kernel/model/assets.go@@ -208,7 +208,7 @@ func SearchAssetsByName(keyword string) (ret []*cache.Asset) {ret = []*cache.Asset{}count := 0- for _, asset := range cache.Assets {+ for _, asset := range cache.GetAssets() {if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) {continue}@@ -471,13 +471,14 @@ func RemoveUnusedAssets() (ret []string) {}indexHistoryDir(filepath.Base(historyDir), NewLute())+ cache.LoadAssets()return}func RemoveUnusedAsset(p string) (ret string) {- p = filepath.Join(util.DataDir, p)- if !gulu.File.IsExist(p) {- return p+ absPath := filepath.Join(util.DataDir, p)+ if !gulu.File.IsExist(absPath) {+ return absPath}historyDir, err := GetHistoryDir(HistoryOpClean)@@ -486,24 +487,25 @@ func RemoveUnusedAsset(p string) (ret string) {return}- newP := strings.TrimPrefix(p, util.DataDir)+ newP := strings.TrimPrefix(absPath, util.DataDir)historyPath := filepath.Join(historyDir, newP)- if gulu.File.IsExist(p) {- if err = gulu.File.Copy(p, historyPath); nil != err {+ if gulu.File.IsExist(absPath) {+ if err = gulu.File.Copy(absPath, historyPath); nil != err {return}- hash, _ := util.GetEtag(p)+ hash, _ := util.GetEtag(absPath)sql.DeleteAssetsByHashes([]string{hash})}- if err = os.RemoveAll(p); nil != err {- logging.LogErrorf("remove unused asset [%s] failed: %s", p, err)+ if err = os.RemoveAll(absPath); nil != err {+ logging.LogErrorf("remove unused asset [%s] failed: %s", absPath, err)}- ret = p+ ret = absPathIncSync()indexHistoryDir(filepath.Base(historyDir), NewLute())+ cache.RemoveAsset(p)return}