mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-08 00:04:21 +01:00
⚡ Improve data indexing to reduce disk read operations https://github.com/siyuan-note/siyuan/issues/16958
Signed-off-by: Daniel <845765@qq.com>
This commit is contained in:
parent
dc00060062
commit
87282404bb
4 changed files with 65 additions and 45 deletions
33
kernel/cache/asset.go
vendored
33
kernel/cache/asset.go
vendored
|
|
@ -34,25 +34,45 @@ type AssetHash struct {
|
|||
}
|
||||
|
||||
var (
|
||||
assetHashCache = map[string]*AssetHash{}
|
||||
assetHashLock = sync.Mutex{}
|
||||
assetHashCache = map[string]*AssetHash{}
|
||||
assetPathHashCache = map[string]*AssetHash{}
|
||||
assetHashLock = sync.Mutex{}
|
||||
)
|
||||
|
||||
func RemoveAssetHash(hash string) {
|
||||
assetHashLock.Lock()
|
||||
defer assetHashLock.Unlock()
|
||||
|
||||
delete(assetHashCache, hash)
|
||||
asset := assetHashCache[hash]
|
||||
if nil != asset {
|
||||
delete(assetHashCache, hash)
|
||||
delete(assetPathHashCache, asset.Path)
|
||||
}
|
||||
}
|
||||
|
||||
func SetAssetHash(hash, path string) {
|
||||
assetHashLock.Lock()
|
||||
defer assetHashLock.Unlock()
|
||||
|
||||
assetHashCache[hash] = &AssetHash{
|
||||
Hash: hash,
|
||||
Path: path,
|
||||
assetHashCache[hash] = &AssetHash{Hash: hash, Path: path}
|
||||
assetPathHashCache[path] = &AssetHash{Hash: hash, Path: path}
|
||||
}
|
||||
|
||||
func GetAssetHashByPath(path string) *AssetHash {
|
||||
assetHashLock.Lock()
|
||||
defer assetHashLock.Unlock()
|
||||
|
||||
asset, exists := assetPathHashCache[path]
|
||||
if exists {
|
||||
if filelock.IsExist(filepath.Join(util.DataDir, asset.Path)) {
|
||||
return asset
|
||||
}
|
||||
|
||||
delete(assetHashCache, asset.Hash)
|
||||
delete(assetPathHashCache, path)
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAssetHash(hash string) *AssetHash {
|
||||
|
|
@ -66,6 +86,7 @@ func GetAssetHash(hash string) *AssetHash {
|
|||
}
|
||||
|
||||
delete(assetHashCache, hash)
|
||||
delete(assetPathHashCache, a.Path)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue