Skip to content

Commit

Permalink
limit time spend on server side for 2nd alternative request and if cu…
Browse files Browse the repository at this point in the history
…stom model request; but allow longer custom model routes
  • Loading branch information
karussell committed Feb 16, 2025
1 parent ce85de7 commit c1a5f56
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/api/Api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ export class ApiImpl implements Api {
if (args.customModel) {
request.custom_model = args.customModel
request['ch.disable'] = true
request['timeout_ms'] = 10000
}

if (
Expand All @@ -302,6 +303,7 @@ export class ApiImpl implements Api {
) {
return {
...request,
timeout_ms: 10000,
'alternative_route.max_paths': args.maxAlternativeRoutes,
algorithm: 'alternative_route',
}
Expand Down
1 change: 1 addition & 0 deletions src/api/graphhopper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface RoutingRequest {
'alternative_route.max_paths'?: number
'alternative_route.max_weight_factor'?: number
'ch.disable'?: boolean
timeout_ms?: number
algorithm?: 'alternative_route' | 'round_trip'
snap_preventions?: string[]
details?: string[]
Expand Down
4 changes: 2 additions & 2 deletions src/stores/QueryStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export default class QueryStore extends Store<QueryStoreState> {
if (maxDistance < 200_000) {
// Use a single request, possibly including alternatives when custom models are enabled.
requests = [QueryStore.buildRouteRequest(state)]
} else if (maxDistance < 500_000) {
} else if (maxDistance < 700_000) {
// Force no alternatives for longer custom model routes.
requests = [
QueryStore.buildRouteRequest({
Expand All @@ -326,7 +326,7 @@ export default class QueryStore extends Store<QueryStoreState> {
'Using the custom model feature is unfortunately not ' +
'possible when the request points are further than ' +
// todo: use settings#showDistanceInMiles, but not sure how to use state from another store here
metersToText(500_000, false) +
metersToText(700_000, false) +
' apart.'
)
)
Expand Down
2 changes: 2 additions & 0 deletions test/routing/Api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ describe('route', () => {
'track_type',
'country',
],
timeout_ms: 10000,
'alternative_route.max_paths': args.maxAlternativeRoutes,
algorithm: 'alternative_route',
}
Expand Down Expand Up @@ -218,6 +219,7 @@ describe('route', () => {
],
custom_model: args.customModel!,
'ch.disable': true,
timeout_ms: 10000,
}

const mockedDispatcher = jest.spyOn(Dispatcher, 'dispatch')
Expand Down

0 comments on commit c1a5f56

Please sign in to comment.