Replace cache with single int64
This commit is contained in:
parent
138080d5e2
commit
c73a53dbe3
|
@ -40,8 +40,12 @@ func IsPathResolutionError(err error) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Filesystem struct {
|
type Filesystem struct {
|
||||||
Server *Server
|
mu sync.RWMutex
|
||||||
cacheDiskMu sync.Mutex
|
|
||||||
|
lastLookupTime time.Time
|
||||||
|
diskUsage int64
|
||||||
|
|
||||||
|
Server *Server
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the root path that contains all of a server's data.
|
// Returns the root path that contains all of a server's data.
|
||||||
|
@ -241,11 +245,11 @@ func (fs *Filesystem) getCachedDiskUsage() (int64, error) {
|
||||||
//
|
//
|
||||||
// This effectively the same speed as running this call in parallel since this cache will return
|
// This effectively the same speed as running this call in parallel since this cache will return
|
||||||
// instantly on the second call.
|
// instantly on the second call.
|
||||||
fs.cacheDiskMu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.cacheDiskMu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
if x, exists := fs.Server.cache.Get("disk_used"); exists {
|
if fs.lastLookupTime.After(time.Now().Add(time.Second * -60)) {
|
||||||
return x.(int64), nil
|
return fs.diskUsage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is no size its either because there is no data (in which case running this function
|
// If there is no size its either because there is no data (in which case running this function
|
||||||
|
@ -257,7 +261,8 @@ func (fs *Filesystem) getCachedDiskUsage() (int64, error) {
|
||||||
// Always cache the size, even if there is an error. We want to always return that value
|
// Always cache the size, even if there is an error. We want to always return that value
|
||||||
// so that we don't cause an endless loop of determining the disk size if there is a temporary
|
// so that we don't cause an endless loop of determining the disk size if there is a temporary
|
||||||
// error encountered.
|
// error encountered.
|
||||||
fs.Server.cache.Set("disk_used", size, time.Second*60)
|
fs.lastLookupTime = time.Now()
|
||||||
|
atomic.StoreInt64(&fs.diskUsage, size)
|
||||||
|
|
||||||
return size, err
|
return size, err
|
||||||
}
|
}
|
||||||
|
@ -416,7 +421,6 @@ func (fs *Filesystem) unsafeStat(p string) (*Stat, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
st := &Stat{
|
st := &Stat{
|
||||||
Info: s,
|
Info: s,
|
||||||
Mimetype: "inode/directory",
|
Mimetype: "inode/directory",
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/creasty/defaults"
|
"github.com/creasty/defaults"
|
||||||
"github.com/gammazero/workerpool"
|
"github.com/gammazero/workerpool"
|
||||||
"github.com/patrickmn/go-cache"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/pterodactyl/wings/api"
|
"github.com/pterodactyl/wings/api"
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
|
@ -98,7 +97,6 @@ func FromConfiguration(data *api.ServerConfigurationResponse) (*Server, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.cache = cache.New(time.Minute*10, time.Minute*15)
|
|
||||||
s.Archiver = Archiver{Server: s}
|
s.Archiver = Archiver{Server: s}
|
||||||
s.Filesystem = Filesystem{Server: s}
|
s.Filesystem = Filesystem{Server: s}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/apex/log"
|
"github.com/apex/log"
|
||||||
"github.com/patrickmn/go-cache"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/pterodactyl/wings/api"
|
"github.com/pterodactyl/wings/api"
|
||||||
"github.com/pterodactyl/wings/environment"
|
"github.com/pterodactyl/wings/environment"
|
||||||
|
@ -37,10 +36,6 @@ type Server struct {
|
||||||
Environment environment.ProcessEnvironment `json:"-"`
|
Environment environment.ProcessEnvironment `json:"-"`
|
||||||
Filesystem Filesystem `json:"-"`
|
Filesystem Filesystem `json:"-"`
|
||||||
|
|
||||||
// Server cache used to store frequently requested information in memory and make
|
|
||||||
// certain long operations return faster. For example, FS disk space usage.
|
|
||||||
cache *cache.Cache
|
|
||||||
|
|
||||||
// Events emitted by the server instance.
|
// Events emitted by the server instance.
|
||||||
emitter *events.EventBus
|
emitter *events.EventBus
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user