diff options
author | Ben Morrison <ben@gbmor.dev> | 2019-06-06 02:20:38 -0400 |
---|---|---|
committer | Ben Morrison <ben@gbmor.dev> | 2019-06-06 02:22:54 -0400 |
commit | 1a15258ee5d93ffef8f8c768ff725d7429a3248c (patch) | |
tree | 9a89321ce5c84509ec778cad3b9abb983026fc8b | |
parent | 7a75c4fc399a1c8e545e9e8d77ecf5bae54a3b96 (diff) | |
download | getwtxt-1a15258ee5d93ffef8f8c768ff725d7429a3248c.tar.gz |
renamed functions
-rw-r--r-- | svc/cache.go | 23 | ||||
-rw-r--r-- | svc/db.go | 8 | ||||
-rw-r--r-- | 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() } } |