From a0892ef77eafd685a447e084c1c07b4edb0b4689 Mon Sep 17 00:00:00 2001 From: Jane Haring <52415314+wwxiaoqi@users.noreply.github.com> Date: Sat, 7 Feb 2026 10:08:50 +0800 Subject: [PATCH] :zap: Optimize asset hash cache lookup (#16892) Co-authored-by: D <845765@qq.com> --- kernel/cache/asset.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/kernel/cache/asset.go b/kernel/cache/asset.go index d3386e3a2..838a189aa 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 - } - - delete(assetHashCache, hash) - delete(assetPathHashCache, a.Path) - return nil - } + // 直接使用 hash 作为 key 进行查找 + asset, exists := assetHashCache[hash] + if !exists { + return nil } - return nil + + // 验证文件是否存在 + if !filelock.IsExist(filepath.Join(util.DataDir, asset.Path)) { + // 文件不存在,清理缓存 + delete(assetHashCache, hash) + return nil + } + return asset } type Asset struct {