2.5 minutes for lookups, not every minute
This commit is contained in:
parent
9eb795b1bb
commit
c7e732d084
|
@ -212,8 +212,6 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
|
||||||
// Because determining the amount of space being used by a server is a taxing operation we
|
// Because determining the amount of space being used by a server is a taxing operation we
|
||||||
// will load it all up into a cache and pull from that as long as the key is not expired.
|
// will load it all up into a cache and pull from that as long as the key is not expired.
|
||||||
func (fs *Filesystem) HasSpaceAvailable() bool {
|
func (fs *Filesystem) HasSpaceAvailable() bool {
|
||||||
space := fs.Server.Build().DiskSpace
|
|
||||||
|
|
||||||
size, err := fs.getCachedDiskUsage()
|
size, err := fs.getCachedDiskUsage()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fs.Server.Log().WithField("error", err).Warn("failed to determine root server directory size")
|
fs.Server.Log().WithField("error", err).Warn("failed to determine root server directory size")
|
||||||
|
@ -223,6 +221,7 @@ func (fs *Filesystem) HasSpaceAvailable() bool {
|
||||||
// been allocated.
|
// been allocated.
|
||||||
fs.Server.Proc().SetDisk(size)
|
fs.Server.Proc().SetDisk(size)
|
||||||
|
|
||||||
|
space := fs.Server.Build().DiskSpace
|
||||||
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
// If space is -1 or 0 just return true, means they're allowed unlimited.
|
||||||
//
|
//
|
||||||
// Technically we could skip disk space calculation because we don't need to check if the server exceeds it's limit
|
// Technically we could skip disk space calculation because we don't need to check if the server exceeds it's limit
|
||||||
|
@ -249,7 +248,8 @@ func (fs *Filesystem) getCachedDiskUsage() (int64, error) {
|
||||||
fs.mu.Lock()
|
fs.mu.Lock()
|
||||||
defer fs.mu.Unlock()
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
if fs.lastLookupTime.After(time.Now().Add(time.Second * -60)) {
|
// Expire the cache after 2.5 minutes.
|
||||||
|
if fs.lastLookupTime.After(time.Now().Add(time.Second * -150)) {
|
||||||
return fs.diskUsage, nil
|
return fs.diskUsage, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user