From 9eeea343d57e78ed1a02e7a9809cbd7b18236515 Mon Sep 17 00:00:00 2001 From: Cole Brown Date: Tue, 26 Jun 2018 17:22:04 -0400 Subject: [PATCH] Update ttlmanager to use ds.Batching --- addr_manager_ds.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/addr_manager_ds.go b/addr_manager_ds.go index 71ed061..75b16c8 100644 --- a/addr_manager_ds.go +++ b/addr_manager_ds.go @@ -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) {