Update ttlmanager to use ds.Batching

This commit is contained in:
Cole Brown 2018-06-26 17:22:04 -04:00
parent 78cd2c5abd
commit 9eeea343d5

View File

@ -231,7 +231,7 @@ type ttlmanager struct {
ctx context.Context
cancel context.CancelFunc
ticker *time.Ticker
ds ds.Datastore
ds ds.Batching
}
func newTTLManager(parent context.Context, d ds.Datastore, tick time.Duration) *ttlmanager {
@ -265,14 +265,23 @@ func (mgr *ttlmanager) tick() {
defer mgr.RUnlock()
now := time.Now()
batch, err := mgr.ds.Batch()
if err != nil {
log.Error(err)
return
}
for key, entry := range mgr.entries {
if entry.ExpiresAt.Before(now) {
if err := mgr.ds.Delete(key); err != nil {
if err := batch.Delete(key); err != nil {
log.Error(err)
}
delete(mgr.entries, key)
}
}
err := batch.Commit()
if err != nil {
log.Error(err)
}
}
func (mgr *ttlmanager) setTTLs(keys []ds.Key, ttl time.Duration) {