diff --git a/import.go b/import.go index 5f4da0d..2c12b7f 100644 --- a/import.go +++ b/import.go @@ -17,7 +17,7 @@ func importPlayerAdvanced(db *gorm.DB) { log.Printf("advanced import failed for %d: %v", season, err) } log.Printf("Advanced import for season: %d", season) - time.Sleep(1300 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) utils.SleepWithJitter(1000 * time.Millisecond) } } @@ -29,7 +29,7 @@ func importPlayerAdvancedPlayoffs(db *gorm.DB) { log.Printf("advanced import failed for %d: %v", season, err) } log.Printf("Advanced Playoffs import for season: %d", season) - time.Sleep(1300 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) utils.SleepWithJitter(1500 * time.Millisecond) } } @@ -41,7 +41,7 @@ func importPlayerTotalsScrape(db *gorm.DB) { log.Printf("scraped totals import failed for %d: %v", season, err) } log.Printf("Player Totals import for season: %d", season) - time.Sleep(1300 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) utils.SleepWithJitter(1250 * time.Millisecond) } } @@ -53,7 +53,7 @@ func importPlayerTotalsPlayoffsScrape(db *gorm.DB) { log.Printf("scraped playoffs import failed for %d: %v", season, err) } log.Printf("Player Playoffs Totals import for season: %d", season) - time.Sleep(1300 * time.Millisecond) + time.Sleep(2000 * time.Millisecond) utils.SleepWithJitter(1700 * time.Millisecond) } } @@ -64,7 +64,7 @@ func importGameSchedules(db *gorm.DB) { months := []string{ // "september", "october", "november", "december", "january", // "february", "march", "april", "may", "june", - "april", "may", "june", + "may", "june", // "february", "march", "april", "may", "june", // "october", "november", "december", } @@ -79,7 +79,7 @@ func importGameSchedules(db *gorm.DB) { } log.Printf("Game schedule import for %s, %d complete.", month, season) // Respectful delay between requests - time.Sleep(1400 * time.Millisecond) + time.Sleep(2500 * time.Millisecond) utils.SleepWithJitter(1800 * time.Millisecond) } log.Printf("--- Finished Game Schedule Import for Season: %d ---", season) diff --git a/utils/middleware/rate_limiter.go b/utils/middleware/rate_limiter.go index 63dadd2..8ec30e8 100644 --- a/utils/middleware/rate_limiter.go +++ b/utils/middleware/rate_limiter.go @@ -1,6 +1,7 @@ package middleware import ( + "strings" "time" "github.com/gofiber/fiber/v2" @@ -9,8 +10,17 @@ import ( func RateLimiter() fiber.Handler { return limiter.New(limiter.Config{ - Max: 30, + Max: 20, Expiration: 1 * time.Minute, + Next: func(c *fiber.Ctx) bool { + // Skip rate limiting for internal services and infra endpoints + ip := c.IP() + if strings.HasPrefix(ip, "10.") || strings.HasPrefix(ip, "172.") || ip == "127.0.0.1" { + return true + } + path := c.Path() + return path == "/metrics" || strings.HasPrefix(path, "/swagger") + }, KeyGenerator: func(c *fiber.Ctx) string { if ip := c.Get("X-Real-IP"); ip != "" { return ip