lib/fs: Cache user lookups (#8496)

This commit is contained in:
Jakob Borg
2022-08-12 07:48:00 +02:00
committed by GitHub
parent 06273875ae
commit eb81f7400c
7 changed files with 85 additions and 16 deletions
+6 -1
View File
@@ -15,6 +15,7 @@ import (
"math/rand"
"net/url"
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
@@ -61,6 +62,8 @@ type fakeFS struct {
insens bool
withContent bool
latency time.Duration
userCache *userCache
groupCache *groupCache
}
type fakeFSCounters struct {
@@ -109,6 +112,8 @@ func newFakeFilesystem(rootURI string, _ ...Option) *fakeFS {
mtime: time.Now(),
children: make(map[string]*fakeEntry),
},
userCache: newValueCache(time.Hour, user.LookupId),
groupCache: newValueCache(time.Hour, user.LookupGroupId),
}
files, _ := strconv.Atoi(params.Get("files"))
@@ -658,7 +663,7 @@ func (fs *fakeFS) SameFile(fi1, fi2 FileInfo) bool {
}
func (fs *fakeFS) PlatformData(name string) (protocol.PlatformData, error) {
return unixPlatformData(fs, name)
return unixPlatformData(fs, name, fs.userCache, fs.groupCache)
}
func (*fakeFS) underlying() (Filesystem, bool) {