Skip to content

Commit e7ee728

Browse files
committed
Fix throttling
1 parent 8c3ebcb commit e7ee728

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

backend/internal/infrastructure/db/mongodb.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,19 @@ func (m *MongoDB) Collection(name string) *mongo.Collection {
4444
}
4545

4646
func (m *MongoDB) EnsureIndexes(ctx context.Context) error {
47+
// Users collection indexes
48+
users := m.Collection("users")
49+
_, err := users.Indexes().CreateOne(ctx, mongo.IndexModel{
50+
Keys: bson.D{{Key: "email", Value: 1}},
51+
Options: options.Index().SetUnique(true),
52+
})
53+
if err != nil {
54+
return err
55+
}
56+
4757
// Events collection indexes
4858
events := m.Collection("events")
49-
_, err := events.Indexes().CreateMany(ctx, []mongo.IndexModel{
59+
_, err = events.Indexes().CreateMany(ctx, []mongo.IndexModel{
5060
{
5161
Keys: bson.D{{Key: "domain_id", Value: 1}, {Key: "timestamp", Value: -1}},
5262
},

backend/internal/utils/hash.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import (
1010
)
1111

1212
func HashPassword(password string) (string, error) {
13-
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
13+
// Using cost 8 instead of 10 for better performance in resource-constrained environments
14+
// Cost 8 = ~40ms on modern CPU, Cost 10 = ~160ms
15+
// Still secure for most applications
16+
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 8)
1417
return string(bytes), err
1518
}
1619

0 commit comments

Comments
 (0)