mirror of
https://github.com/nprasad2077/NBA_Go.git
synced 2026-09-22 05:55:13 +00:00
limiter changes and import changes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user