From 1a15258ee5d93ffef8f8c768ff725d7429a3248c Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Thu, 6 Jun 2019 02:20:38 -0400 Subject: renamed functions --- svc/cache.go | 23 ++++------------------- svc/db.go | 8 ++++---- svc/db_test.go | 4 ++-- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/svc/cache.go b/svc/cache.go index ce3813c..fb6a9ab 100644 --- a/svc/cache.go +++ b/svc/cache.go @@ -8,7 +8,7 @@ import ( "time" ) -func checkCacheTime() bool { +func cacheTimer() bool { confObj.Mu.RLock() answer := time.Since(confObj.LastCache) > confObj.CacheInterval confObj.Mu.RUnlock() @@ -20,11 +20,11 @@ func checkCacheTime() bool { // for the update intervals to pass. func cacheAndPush() { for { - if checkCacheTime() { + if cacheTimer() { refreshCache() } - if checkDBtime() { - if err := pushDatabase(); err != nil { + if dbTimer() { + if err := pushDB(); err != nil { log.Printf("Error pushing cache to database: %v\n", err.Error()) } } @@ -113,18 +113,3 @@ func pingAssets() { staticCache.cssMod = cssStat.ModTime() } } - -// Simple function to deduplicate entries in a []string -func dedupe(list []string) []string { - var out []string - var seen = map[string]bool{} - - for _, e := range list { - if !seen[e] { - out = append(out, e) - seen[e] = true - } - } - - return out -} diff --git a/svc/db.go b/svc/db.go index 10ea28d..2289771 100644 --- a/svc/db.go +++ b/svc/db.go @@ -37,10 +37,10 @@ func initDatabase() { dbChan <- db - pullDatabase() + pullDB() } -func checkDBtime() bool { +func dbTimer() bool { confObj.Mu.RLock() answer := time.Since(confObj.LastPush) > confObj.DBInterval confObj.Mu.RUnlock() @@ -50,14 +50,14 @@ func checkDBtime() bool { // Pushes the registry's cache data to a local // database for safe keeping. -func pushDatabase() error { +func pushDB() error { db := <-dbChan dbChan <- db return db.push() } -func pullDatabase() { +func pullDB() { db := <-dbChan dbChan <- db db.pull() diff --git a/svc/db_test.go b/svc/db_test.go index 071936e..f3252c6 100644 --- a/svc/db_test.go +++ b/svc/db_test.go @@ -73,7 +73,7 @@ func Benchmark_pushDatabase(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - err := pushDatabase() + err := pushDB() if err != nil { b.Errorf("%v\n", err) } @@ -87,6 +87,6 @@ func Benchmark_pullDatabase(b *testing.B) { } for i := 0; i < b.N; i++ { - pullDatabase() + pullDB() } } -- cgit 1.4.1-2-gfad0