Cache total stats in memory

This commit is contained in:
2021-11-03 21:24:23 +01:00
parent 492c88c5b2
commit bd6eafd9f7
8 changed files with 177 additions and 36 deletions

View File

@@ -47,6 +47,26 @@ func TestPostgresStoreWithCache(t *testing.T) {
testLoginAttemptStore(s, t)
}
func BenchmarkPostgresStore(b *testing.B) {
var dsn string
var found bool
dsn, found = os.LookupEnv("APIARY_TEST_POSTGRES_DSN")
if !found {
b.Skipf("APIARY_TEST_POSTGRES_DSN not set. Skipping.")
}
dropPGDatabase(dsn)
setupFunc := func() store.LoginAttemptStore {
dropPGDatabase(dsn)
pgs, err := store.NewPostgresStore(dsn)
if err != nil {
b.Fatalf("Error getting store: %s", err)
}
pgs.InitDB()
return pgs
}
benchmarkLoginAttemptStore(setupFunc, b)
dropPGDatabase(dsn)
}
func dropPGDatabase(dsn string) {
db, err := sql.Open("pgx", dsn)
@@ -54,8 +74,5 @@ func dropPGDatabase(dsn string) {
panic(err)
}
_, err = db.Exec("DROP TABLE login_attempts")
if err != nil {
panic(err)
}
_, _ = db.Exec("DROP TABLE login_attempts")
}