Skip to content

Avoid Unnecessary Flex Requests #1372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/actions/api-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { TransportMode } from '@opentripplanner/types'

export const countFlexModes = (modes: TransportMode[]): number =>
modes.filter((m) => m.mode === 'FLEX').length
12 changes: 11 additions & 1 deletion lib/actions/apiV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
import { isLastStop } from '../util/stop-times'

import { addToRecentSearches, rememberPlace } from './user'
import { countFlexModes } from './api-utils'
import {
createQueryAction,
fetchingStopTimesForStop,
Expand Down Expand Up @@ -1039,7 +1040,16 @@ export function routingQuery(searchId = null, updateSearchInReducer) {
// Generate combinations if the modes for query are not specified in the query
// FIXME: BICYCLE_RENT does not appear in this list unless TRANSIT is also enabled.
// This is likely due to the fact that BICYCLE_RENT is treated as a transit submode.
const combinations = modes ? [baseQuery] : generateCombinations(baseQuery)
let combinations = modes ? [baseQuery] : generateCombinations(baseQuery)

// Pre-planConnection API hack: FLEX should always be bundled together.
// The real solution is to change how we generate mode selections, but for now
// this removes superfluous flex requests.
combinations = combinations.filter((c) => {
const flexCount = countFlexModes(c.modes)
// We need either all 3 flex modes or none! Anything in-between is invalid
return flexCount === 0 || flexCount === 3
})

if (combinations.length === 0) {
return RoutingQueryCallResult.INVALID_MODE_SELECTION
Expand Down
Loading