Optimize asset hash cache lookup (#16892)

Co-authored-by: D <845765@qq.com>
This commit is contained in:
Jane Haring 2026-02-07 10:08:50 +08:00 committed by GitHub
parent ac184d61fa
commit a0892ef77e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

23
kernel/cache/asset.go vendored
View file

@ -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 {