fix: address code review findings
This commit is contained in:
@@ -418,21 +418,21 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions, closedSta
|
|||||||
|
|
||||||
newDurationWithMCT := newDuration + transferTime
|
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
|
|
||||||
|
|
||||||
newTransfers := current.transfers
|
newTransfers := current.transfers
|
||||||
if edge.IsTransfer {
|
if edge.IsTransfer {
|
||||||
newTransfers++
|
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
|
||||||
|
|
||||||
// Build new itinerary legs
|
// Build new itinerary legs
|
||||||
newLegs := make([]RouteLeg, len(current.itinerary.Legs)+1)
|
newLegs := make([]RouteLeg, len(current.itinerary.Legs)+1)
|
||||||
copy(newLegs, current.itinerary.Legs)
|
copy(newLegs, current.itinerary.Legs)
|
||||||
@@ -831,27 +831,6 @@ func (g *Graph) ApplyMCT(itinerary *Itinerary, mctBase int) *Itinerary {
|
|||||||
|
|
||||||
// Add the MCT to the total duration (as waiting time at transfer)
|
// Add the MCT to the total duration (as waiting time at transfer)
|
||||||
totalMCT += mct
|
totalMCT += mct
|
||||||
}
|
|
||||||
|
|
||||||
// Update leg durations to include MCT for transfer legs
|
|
||||||
for i := 1; i < len(adjustedLegs); i++ {
|
|
||||||
prevLeg := &adjustedLegs[i-1]
|
|
||||||
currLeg := &adjustedLegs[i]
|
|
||||||
|
|
||||||
// Determine MCT based on node types and transfer kinds
|
|
||||||
mct := mctBase
|
|
||||||
|
|
||||||
// Reduce MCT for city hub transfers (the transfer point node is a city)
|
|
||||||
// The transfer point is the destination of the previous leg / start of current leg
|
|
||||||
transferPoint := prevLeg.To // = currLeg.From
|
|
||||||
if transferPoint.Type == NodeTypeCity {
|
|
||||||
mct = mctBase / 2 // 30 min -> 15 min for city hub transfers
|
|
||||||
}
|
|
||||||
|
|
||||||
// Increase MCT for mode changes (different transport types)
|
|
||||||
if prevLeg.Transport != currLeg.Transport {
|
|
||||||
mct = mctBase + 600 // 30 min + 10 min for mode change
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add MCT to the current leg's duration (transfer wait time)
|
// Add MCT to the current leg's duration (transfer wait time)
|
||||||
adjustedLegs[i].Duration += mct
|
adjustedLegs[i].Duration += mct
|
||||||
|
|||||||
@@ -170,7 +170,6 @@ func (c *Client) Do(ctx context.Context, method, path string, query map[string]s
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c.circuitBreaker.recordFailure() // final failure
|
|
||||||
c.metrics.RecordCircuitBreakerTrip()
|
c.metrics.RecordCircuitBreakerTrip()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -299,7 +298,7 @@ func buildURL(path string, query map[string]string) string {
|
|||||||
return u
|
return u
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- Token Bucket Rate Limitter ---
|
// --- Token Bucket Rate Limiter ---
|
||||||
|
|
||||||
func newTokenBucket(capacity, perSeconds int) *tokenBucket {
|
func newTokenBucket(capacity, perSeconds int) *tokenBucket {
|
||||||
return &tokenBucket{
|
return &tokenBucket{
|
||||||
@@ -322,7 +321,7 @@ func (tb *tokenBucket) acquire() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf("rate limit: rate exceeded (%.1f TPS configured)", float64(tb.refillPerSec)/float64(time.Second))
|
return fmt.Errorf("rate limit: rate exceeded (%.1f TPS configured)", float64(tb.refillPerSec))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tb *tokenBucket) refill(now time.Time) {
|
func (tb *tokenBucket) refill(now time.Time) {
|
||||||
|
|||||||
Reference in New Issue
Block a user