mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-08 00:04:21 +01:00
⚡ Optimize asset hash cache lookup (#16892)
Co-authored-by: D <845765@qq.com>
This commit is contained in:
parent
ac184d61fa
commit
a0892ef77e
1 changed files with 12 additions and 11 deletions
23
kernel/cache/asset.go
vendored
23
kernel/cache/asset.go
vendored
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue