fix: address code review findings

This commit is contained in:
2026-08-19 13:26:05 +03:00
parent 4a7be531ed
commit c2bdffb0ab
2 changed files with 25 additions and 8 deletions

View File

@@ -1108,7 +1108,7 @@ func (g *Graph) checkRouteForChanges(itinerary *Itinerary) bool {
}
// Check for significant delay (more than 2x normal duration)
if edge.Duration > leg.Duration*2 && leg.Duration > 0 {
if !needsReSearch || itinerary.ReSearchReason == string(reasonNone) {
if !needsReSearch {
needsReSearch = true
itinerary.NeedsReSearch = true
itinerary.ReSearchReason = string(reasonMajorDelay)
@@ -1131,8 +1131,8 @@ func (g *Graph) rescheduleRoute(originID, destID string, opts SearchOptions, clo
result := g.FindRoute(originID, destID, opts, closedStations, neighbors, yclient...)
if result != nil {
result.LastChecked = time.Now().Unix()
result.NeedsReSearch = false
result.ReSearchReason = string(reasonNone)
// Keep NeedsReSearch and ReSearchReason from the original itinerary to indicate
// that a re-search was triggered due to changes
}
return result
}
@@ -1141,7 +1141,13 @@ func (g *Graph) rescheduleRoute(originID, destID string, opts SearchOptions, clo
// This is the main entry point for flight change notification logic.
func (g *Graph) CheckAndRescheduleRoute(itinerary *Itinerary, originID, destID string, opts SearchOptions, closedStations map[string]bool, neighbors map[string][]storage.StationNeighbor, yclient ...*yandex.Client) *Itinerary {
if g.checkRouteForChanges(itinerary) {
return g.rescheduleRoute(originID, destID, opts, closedStations, neighbors, yclient...)
result := g.rescheduleRoute(originID, destID, opts, closedStations, neighbors, yclient...)
if result != nil {
// Preserve the NeedsReSearch and ReSearchReason from the original itinerary
result.NeedsReSearch = itinerary.NeedsReSearch
result.ReSearchReason = itinerary.ReSearchReason
}
return result
}
return itinerary
}