Cache total stats in memory
This commit is contained in:
@@ -188,6 +188,52 @@ func testLoginAttemptStore(s store.LoginAttemptStore, t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func benchmarkLoginAttemptStore(setupFunc func() store.LoginAttemptStore, b *testing.B) {
|
||||
b.Run("BenchmarkAdd", func(b *testing.B) {
|
||||
s := setupFunc()
|
||||
for i := 0; i < b.N; i++ {
|
||||
attempt := randomAttempts(1)
|
||||
err := s.AddAttempt(attempt[0])
|
||||
if err != nil {
|
||||
b.Fatalf("Error adding attempt: %s", err)
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("BenchmarkAdd10k", func(b *testing.B) {
|
||||
attempts := randomAttempts(10_000)
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
s := setupFunc()
|
||||
b.StartTimer()
|
||||
for _, attempt := range attempts {
|
||||
err := s.AddAttempt(attempt)
|
||||
if err != nil {
|
||||
b.Fatalf("Error adding attempt: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
b.Run("BenchmarkAll10k", func(b *testing.B) {
|
||||
s := setupFunc()
|
||||
attempts := randomAttempts(10_000)
|
||||
for _, attempt := range attempts {
|
||||
err := s.AddAttempt(attempt)
|
||||
if err != nil {
|
||||
b.Fatalf("Error adding attempt: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
all, err := s.All()
|
||||
if err != nil {
|
||||
b.Fatalf("Error fetchin all: %s", err)
|
||||
}
|
||||
_ = len(all)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func randomAttempts(count int) []*models.LoginAttempt {
|
||||
var attempts []*models.LoginAttempt
|
||||
for i := 0; i < count; i++ {
|
||||
|
Reference in New Issue
Block a user