cache read performance improvements

This commit is contained in:
ston1th 2022-05-19 01:29:23 +02:00
commit f69d3149f3
14 changed files with 140 additions and 71 deletions

View file

@ -135,6 +135,7 @@ func (fs *FS) OpenDst(name string) (f http.File, err error) {
f = &File{
log: log.WithName("file"),
f: file,
cache: file,
md: md,
offline: true,
}
@ -198,13 +199,25 @@ func (fs *FS) Open(name string) (f http.File, err error) {
f = &Dir{log: log.WithName("dir"), f: file, dc: fs.dc}
return
}
md := fs.mh.Metadata(name, fi.Size())
var cache provider.File
if offline {
log.V(2).Info("file offline mode")
cache = file
} else {
cache, err = fs.dst.Open(name)
if err != nil {
if !skipLog(name) {
log.Error(err, "error opening cache file")
}
return
}
}
md := fs.mh.Metadata(name, fi.Size())
f = &File{
log: log.WithName("file"),
f: file,
cache: cache,
md: md,
offline: offline,
}
@ -231,7 +244,7 @@ func (fs *FS) openCacheFile(name string, size int64) (df provider.File, err erro
log.Error(err, "error opening cache file")
return
}
if truncate {
if truncate && size > 0 {
err = df.Truncate(size)
if err != nil {
log.Error(err, "error truncating cache file")