Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:zap: Optimize asset hash cache lookup (#16892)

Jane Haringa0892ef77eaf
diff --git a/kernel/cache/asset.go b/kernel/cache/asset.go
index d3386e3a2f..838a189aa5 100644
--- a/kernel/cache/asset.go
+++ b/kernel/cache/asset.go
@@ -79,18 +79,19 @@ func GetAssetHash(hash string) *AssetHash {
assetHashLock.Lock()
defer assetHashLock.Unlock()
- for _, a := range assetHashCache {
- if a.Hash == hash {
- if filelock.IsExist(filepath.Join(util.DataDir, a.Path)) {
- return a
- }
+ // 直接使用 hash 作为 key 进行查找
+ asset, exists := assetHashCache[hash]
+ if !exists {
+ return nil
+ }
- delete(assetHashCache, hash)
- delete(assetPathHashCache, a.Path)
- return nil
- }
+ // 验证文件是否存在
+ if !filelock.IsExist(filepath.Join(util.DataDir, asset.Path)) {
+ // 文件不存在,清理缓存
+ delete(assetHashCache, hash)
+ return nil
}
- return nil
+ return asset
}
type Asset struct {