fix: address code review findings
This commit is contained in:
@@ -557,21 +557,22 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
|
||||
newDurationWithMCT := newDuration + transferTime
|
||||
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if current.transfers+1 > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = current.transfers + 1
|
||||
|
||||
// Calculate new transfers before checking visited
|
||||
newTransfers := current.transfers
|
||||
if edge.IsTransfer {
|
||||
newTransfers++
|
||||
}
|
||||
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if newTransfers > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = newTransfers
|
||||
|
||||
newLegs := make([]RouteLeg, len(current.itinerary.Legs)+1)
|
||||
copy(newLegs, current.itinerary.Legs)
|
||||
|
||||
@@ -733,21 +734,22 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
||||
|
||||
newDurationWithMCT := newDuration + transferTime
|
||||
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if current.transfers+1 > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = current.transfers + 1
|
||||
|
||||
// Calculate new transfers before checking visited
|
||||
newTransfers := current.transfers
|
||||
if edge.IsTransfer {
|
||||
newTransfers++
|
||||
}
|
||||
|
||||
// Check if we've visited this node with fewer transfers
|
||||
visKey := nextNode.ID
|
||||
if existingTransfers, ok := visited[visKey]; ok {
|
||||
if newTransfers > existingTransfers {
|
||||
// Already visited this node with fewer transfers, skip
|
||||
continue
|
||||
}
|
||||
}
|
||||
visited[visKey] = newTransfers
|
||||
|
||||
newLegs := make([]RouteLeg, len(current.itinerary.Legs)+1)
|
||||
copy(newLegs, current.itinerary.Legs)
|
||||
|
||||
|
||||
@@ -398,10 +398,10 @@ func TestRouteReSearchOnChange(t *testing.T) {
|
||||
// We need to do this after the check runs, so let's verify the initial state first.
|
||||
|
||||
// Verify that initial state has NeedsReSearch false (no changes simulated yet)
|
||||
if !itinerary.NeedsReSearch {
|
||||
t.Log("PASS: Initial NeedsReSearch is false (no changes simulated)")
|
||||
if itinerary.NeedsReSearch {
|
||||
t.Errorf("expected initial NeedsReSearch to be false, got true")
|
||||
} else {
|
||||
t.Log("INFO: Initial NeedsReSearch is already true")
|
||||
t.Log("PASS: Initial NeedsReSearch is false (no changes simulated)")
|
||||
}
|
||||
|
||||
// Now simulate cancellation by setting edge s1->s2 duration to > 86400 (1 day = cancellation)
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
@@ -197,10 +196,9 @@ func (c *Client) executeRequest(ctx context.Context, url string) (*Response, err
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("request failed: %w", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
io.ReadAll(resp.Body) // Drain body to allow connection reuse
|
||||
resp.Body.Close()
|
||||
return nil, newAPIError(resp.StatusCode, resp.Status)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user