feat: lazy graph expansion - hub station selection, on-demand /search, and transfer depth limiting
- Remove Population field from HubStation; hub selection now uses only outgoing flights criterion - Simplify SelectHubStations criteria (minPopulation removed from function calls) - Add synthetic edge fallback in FindRoute when lazy expansion fails - Add ResetCircuitBreaker helper to yandex client for test reset - Update test criteria to match new hub selection logic - Remove TestLazySearchCacheIntegration (replaced by integration tests)
This commit is contained in:
@@ -53,8 +53,8 @@ const (
|
||||
|
||||
// hubCriteria defines the criteria for selecting hub stations.
|
||||
type hubCriteria struct {
|
||||
minPopulation int // minimum city population in millions to be considered a hub
|
||||
minOutgoingFlights int // minimum number of outgoing Yandex flights to be considered a hub
|
||||
minPopulation int // minimum city population (millions) to be considered a hub
|
||||
defaultOutgoingFlights int // default outgoing flights count when data is unavailable
|
||||
}
|
||||
|
||||
@@ -66,8 +66,6 @@ type HubStation struct {
|
||||
CityCode string
|
||||
// OutgoingFlights is the estimated number of outgoing Yandex flights from this station.
|
||||
OutgoingFlights int
|
||||
// Population is the city population in millions used for hub selection.
|
||||
Population int
|
||||
// IsHub indicates whether this station meets the hub criteria.
|
||||
IsHub bool
|
||||
}
|
||||
@@ -93,13 +91,12 @@ func SelectHubStations(stations []StationInfo, criteria hubCriteria) HubStationS
|
||||
Station: &Node{ID: si.ID, Type: NodeTypeStation, Name: si.Name, CityCode: si.CityCode},
|
||||
CityCode: si.CityCode,
|
||||
OutgoingFlights: criteria.defaultOutgoingFlights,
|
||||
Population: 0, // will be inferred from city code later
|
||||
IsHub: false,
|
||||
}
|
||||
|
||||
// A station is considered a hub if:
|
||||
// 1. It has >= minOutgoingFlights (outgoing Yandex flight data available) - primary criterion
|
||||
// For MVP, outgoing flights is the primary criterion.
|
||||
// A station is considered a hub if it has >= minOutgoingFlights outgoing Yandex flights.
|
||||
// Population-based selection (minPopulation) is tracked for future implementation;
|
||||
// currently only the outgoing flights criterion is enforced.
|
||||
hasOutgoingFlights := hub.OutgoingFlights >= criteria.minOutgoingFlights
|
||||
|
||||
if hasOutgoingFlights {
|
||||
@@ -573,8 +570,8 @@ func expandFromCityHub(g *Graph, from *Node, destCityCode string, date string, o
|
||||
|
||||
if foundEdges {
|
||||
// Edges already added to graph during cache miss fetch
|
||||
// Return cached data indicating success
|
||||
return []byte("found_edges"), nil
|
||||
// Return a marker indicating success; GetSearch caller only checks err != nil
|
||||
return []byte("1"), nil
|
||||
}
|
||||
|
||||
// Return error to trigger synthetic fallback
|
||||
@@ -716,7 +713,10 @@ func (g *Graph) FindRoute(originID, destID string, opts SearchOptions) *Itinerar
|
||||
// Expand from this node using lazy expansion
|
||||
// Use the destination city code and date from search options for /search calls
|
||||
if opts.DestCityCode != "" && opts.Date != "" {
|
||||
g.ExpandGraphLazy(g.currentNodeByID(current.nodeID), opts.DestCityCode, opts.Date, &opts)
|
||||
if err := g.ExpandGraphLazy(g.currentNodeByID(current.nodeID), opts.DestCityCode, opts.Date, &opts); err != nil {
|
||||
// Expansion failed (e.g., API error, node not found) — fall back to synthetic edges
|
||||
addSyntheticEdgesForNode(g, current.nodeID)
|
||||
}
|
||||
} else {
|
||||
// If no dest city/code available, add synthetic edges as fallback
|
||||
addSyntheticEdgesForNode(g, current.nodeID)
|
||||
|
||||
Reference in New Issue
Block a user