Simplifying memory sleep logic

master
Frederick F. Kautz IV 10 years ago
parent 362305d898
commit 8fcb697844
  1. 10
      pkg/storage/drivers/memory/memory.go

@ -484,13 +484,10 @@ func (memory *memoryDriver) expireObjects() {
return return
} }
var keysToRemove []string var keysToRemove []string
if len(memory.objectMetadata) > 0 {
memory.lock.RLock() memory.lock.RLock()
var earliest time.Time var earliest time.Time
empty := true
for key, object := range memory.objectMetadata { for key, object := range memory.objectMetadata {
if empty {
empty = false
}
if time.Now().Add(-memory.expiration).After(object.metadata.Created) { if time.Now().Add(-memory.expiration).After(object.metadata.Created) {
keysToRemove = append(keysToRemove, key) keysToRemove = append(keysToRemove, key)
} else { } else {
@ -505,13 +502,12 @@ func (memory *memoryDriver) expireObjects() {
memory.objects.Remove(key) memory.objects.Remove(key)
} }
memory.lock.Unlock() memory.lock.Unlock()
if empty {
time.Sleep(memory.expiration)
} else {
sleepFor := earliest.Sub(time.Now()) sleepFor := earliest.Sub(time.Now())
if sleepFor > 0 { if sleepFor > 0 {
time.Sleep(sleepFor) time.Sleep(sleepFor)
} }
} else {
time.Sleep(memory.expiration)
} }
} }
} }

Loading…
Cancel
Save