fix: address code review findings
- Fix type mismatch in search_cache.go: SearchWithCache now returns *yandex.Response instead of *Itinerary - Fix token bucket refill logic in yandex/client.go to properly accumulate tokens based on refillPerSec - Fix hardcoded API key in main.go to load from YANDEX_API_KEY environment variable - Fix missing error handling for JSON encoding in handlers.go RouteGeoJSON function - Fix incorrect redis.Nil handling in cache/store.go CacheAside.Exists method - Fix incorrect error return type in station_status.go updateStationStatus to return newStatus instead of empty string
This commit is contained in:
@@ -175,22 +175,22 @@ func (sm *StationMonitor) updateStationStatus(ctx context.Context, tripCount int
|
||||
|
||||
// Write updated status to cache with 24h TTL
|
||||
if err := sm.Cache.Set(ctx, cacheKey, []byte(newStatus), 24*time.Hour); err != nil {
|
||||
return "", fmt.Errorf("cache set status: %w", err)
|
||||
return newStatus, fmt.Errorf("cache set status: %w", err)
|
||||
}
|
||||
|
||||
// Write updated zero days count to cache with 24h TTL
|
||||
if err := sm.Cache.Set(ctx, zeroDaysKey, []byte(fmt.Sprintf("%d", zeroDays)), 24*time.Hour); err != nil {
|
||||
return "", fmt.Errorf("cache set zero days: %w", err)
|
||||
return newStatus, fmt.Errorf("cache set zero days: %w", err)
|
||||
}
|
||||
|
||||
// Write updated zero-since timestamp to cache with 24h TTL
|
||||
if err := sm.Cache.Set(ctx, zeroSinceKey, []byte(fmt.Sprintf("%d", zeroSince.Unix())), 24*time.Hour); err != nil {
|
||||
return "", fmt.Errorf("cache set zero since: %w", err)
|
||||
return newStatus, fmt.Errorf("cache set zero since: %w", err)
|
||||
}
|
||||
|
||||
// Write updated last-seen-flight timestamp to cache with 24h TTL
|
||||
if err := sm.Cache.Set(ctx, lastSeenFlightKey, []byte(fmt.Sprintf("%d", lastSeenFlight.Unix())), 24*time.Hour); err != nil {
|
||||
return "", fmt.Errorf("cache set last seen flight: %w", err)
|
||||
return newStatus, fmt.Errorf("cache set last seen flight: %w", err)
|
||||
}
|
||||
|
||||
return newStatus, nil
|
||||
|
||||
@@ -235,7 +235,6 @@ func TestProcessStation_Reactivation_AfterClosure(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TestAutoClosureChronology verifies the chronology of auto-closure detection.
|
||||
// It tests that a station closes after exactly N=3 consecutive zero-trip days,
|
||||
// and that it reactivates when trips resume.
|
||||
@@ -337,4 +336,3 @@ func TestAutoClosureChronology(t *testing.T) {
|
||||
t.Errorf("expected zero days 0 after reactivation, got %d", zeroDays4)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user