Cache total stats in memory
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
Reference in New Issue
Block a user