Skip to content

Commit

Permalink
2.5 minutes for lookups, not every minute
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Aug 25, 2020
1 parent 9eb795b commit c7e732d
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions server/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
// 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 {
space := fs.Server.Build().DiskSpace

size, err := fs.getCachedDiskUsage()
if err != nil {
fs.Server.Log().WithField("error", err).Warn("failed to determine root server directory size")
Expand All @@ -223,6 +221,7 @@ func (fs *Filesystem) HasSpaceAvailable() bool {
// been allocated.
fs.Server.Proc().SetDisk(size)

space := fs.Server.Build().DiskSpace
// 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
Expand All @@ -249,7 +248,8 @@ func (fs *Filesystem) getCachedDiskUsage() (int64, error) {
fs.mu.Lock()
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
}

Expand Down

0 comments on commit c7e732d

Please sign in to comment.