Skip to content

Commit 2aa9558

Browse files
Merge pull request #1372 from opentripplanner/flex-request-limiting
Avoid Unnecessary Flex Requests
2 parents 7147a2a + bde6e63 commit 2aa9558

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Diff for: lib/actions/api-utils.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { TransportMode } from '@opentripplanner/types'
2+
3+
export const countFlexModes = (modes: TransportMode[]): number =>
4+
modes.filter((m) => m.mode === 'FLEX').length

Diff for: lib/actions/apiV2.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
import { isLastStop } from '../util/stop-times'
3838

3939
import { addToRecentSearches, rememberPlace } from './user'
40+
import { countFlexModes } from './api-utils'
4041
import {
4142
createQueryAction,
4243
fetchingStopTimesForStop,
@@ -1039,7 +1040,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
10391040
// Generate combinations if the modes for query are not specified in the query
10401041
// FIXME: BICYCLE_RENT does not appear in this list unless TRANSIT is also enabled.
10411042
// This is likely due to the fact that BICYCLE_RENT is treated as a transit submode.
1042-
const combinations = modes ? [baseQuery] : generateCombinations(baseQuery)
1043+
let combinations = modes ? [baseQuery] : generateCombinations(baseQuery)
1044+
1045+
// Pre-planConnection API hack: FLEX should always be bundled together.
1046+
// The real solution is to change how we generate mode selections, but for now
1047+
// this removes superfluous flex requests.
1048+
combinations = combinations.filter((c) => {
1049+
const flexCount = countFlexModes(c.modes)
1050+
// We need either all 3 flex modes or none! Anything in-between is invalid
1051+
return flexCount === 0 || flexCount === 3
1052+
})
10431053

10441054
if (combinations.length === 0) {
10451055
return RoutingQueryCallResult.INVALID_MODE_SELECTION

0 commit comments

Comments
 (0)