summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--svc/cache.go3
-rw-r--r--svc/cache_test.go28
-rw-r--r--svc/conf.go5
-rw-r--r--svc/init_test.go4
-rw-r--r--svc/leveldb.go4
-rw-r--r--svc/sqlite.go4
6 files changed, 10 insertions, 38 deletions
diff --git a/svc/cache.go b/svc/cache.go
index 3383016..d3ac872 100644
--- a/svc/cache.go
+++ b/svc/cache.go
@@ -66,9 +66,6 @@ func cacheUpdate() {
 		errLog("Error refreshing local copy of remote registry data: ", twtxtCache.CrawlRemoteRegistry(v))
 	}
 	remoteRegistries.Mu.RUnlock()
-	confObj.Mu.Lock()
-	confObj.LastCache = time.Now()
-	confObj.Mu.Unlock()
 }
 
 // pingAssets checks if the local static assets
diff --git a/svc/cache_test.go b/svc/cache_test.go
index 28e5c0b..2177917 100644
--- a/svc/cache_test.go
+++ b/svc/cache_test.go
@@ -4,26 +4,9 @@ import (
 	"testing"
 )
 
-func Test_cacheUpdate(t *testing.T) {
-	initTestConf()
-	confObj.Mu.RLock()
-	prevtime := confObj.LastCache
-	confObj.Mu.RUnlock()
-
-	t.Run("Cache Time Check", func(t *testing.T) {
-		cacheUpdate()
-		confObj.Mu.RLock()
-		newtime := confObj.LastCache
-		confObj.Mu.RUnlock()
-
-		if !newtime.After(prevtime) || newtime == prevtime {
-			t.Errorf("Cache time did not update, check cacheUpdate() logic\n")
-		}
-	})
-}
-
 func Benchmark_cacheUpdate(b *testing.B) {
 	initTestConf()
+	mockRegistry()
 	b.ResetTimer()
 
 	for i := 0; i < b.N; i++ {
@@ -37,5 +20,14 @@ func Benchmark_pingAssets(b *testing.B) {
 
 	for i := 0; i < b.N; i++ {
 		pingAssets()
+
+		// We'll only have to reload the cache occasionally,
+		// so only start with an empty staticCache 25% of
+		// the time.
+		if float64(i) > (float64(b.N) * .75) {
+			b.StopTimer()
+			staticCache = &staticAssets{}
+			b.StartTimer()
+		}
 	}
 }
diff --git a/svc/conf.go b/svc/conf.go
index ccd819c..8abb4a6 100644
--- a/svc/conf.go
+++ b/svc/conf.go
@@ -24,8 +24,6 @@ type Configuration struct {
 	StdoutLogging bool          `yaml:"StdoutLogging"`
 	CacheInterval time.Duration `yaml:"StatusFetchInterval"`
 	DBInterval    time.Duration `yaml:"DatabasePushInterval"`
-	LastCache     time.Time     `yaml:"-"`
-	LastPush      time.Time     `yaml:"-"`
 	Instance      `yaml:"Instance"`
 }
 
@@ -249,9 +247,6 @@ func bindConfig() {
 	confObj.DBInterval = viper.GetDuration("DatabasePushInterval")
 	log.Printf("Database push interval: %v\n", confObj.DBInterval)
 
-	confObj.LastCache = time.Now()
-	confObj.LastPush = time.Now()
-
 	confObj.Instance.Vers = Vers
 	confObj.Instance.Name = viper.GetString("Instance.SiteName")
 	confObj.Instance.URL = viper.GetString("Instance.URL")
diff --git a/svc/init_test.go b/svc/init_test.go
index 51c969a..8b68839 100644
--- a/svc/init_test.go
+++ b/svc/init_test.go
@@ -7,7 +7,6 @@ import (
 	"os"
 	"strings"
 	"sync"
-	"time"
 
 	"github.com/getwtxt/registry"
 	"github.com/spf13/viper"
@@ -80,9 +79,6 @@ func testConfig() {
 	confObj.DBInterval = viper.GetDuration("DatabasePushInterval")
 	log.Printf("Database push interval: %v\n", confObj.DBInterval)
 
-	confObj.LastCache = time.Now()
-	confObj.LastPush = time.Now()
-
 	confObj.Instance.Vers = Vers
 	confObj.Instance.Name = viper.GetString("Instance.SiteName")
 	confObj.Instance.URL = viper.GetString("Instance.URL")
diff --git a/svc/leveldb.go b/svc/leveldb.go
index c39bcbf..36b7946 100644
--- a/svc/leveldb.go
+++ b/svc/leveldb.go
@@ -38,10 +38,6 @@ func (lvl *dbLevel) push() error {
 	}
 	remoteRegistries.Mu.RUnlock()
 
-	confObj.Mu.Lock()
-	confObj.LastPush = time.Now()
-	confObj.Mu.Unlock()
-
 	return lvl.db.Write(dbBasket, nil)
 }
 
diff --git a/svc/sqlite.go b/svc/sqlite.go
index 40a7ff2..dd6d6de 100644
--- a/svc/sqlite.go
+++ b/svc/sqlite.go
@@ -43,10 +43,6 @@ func initSqlite() *dbSqlite {
 }
 
 func (lite *dbSqlite) push() error {
-	confObj.Mu.Lock()
-	confObj.LastPush = time.Now()
-	confObj.Mu.Unlock()
-
 	if err := lite.db.Ping(); err != nil {
 		lite = initSqlite()
 	}