fix(map): draw a reopened trip's routes from the device at once

The rounds that pace their router requests told a cached leg from a request by how long it took, anything past 60 ms counting as a request. Since routes are kept on the device, a leg read back after a reload is an IndexedDB read, which on a page busy drawing the map often takes longer, so every leg waited out a request's pause and the trip filled in one leg a second as if it were routed again. The whole trip's route, the road trip day rounds and the join release now count whether a router actually answered. A relay that refused also kept its rest only in memory, so every reload asked it again for the first day; the rest now holds on the device until it ends.

Closes #3228
This commit is contained in:
Maurice
2026-11-28 22:12:59 +01:00
parent 7c0c749bcc
commit 5989ba5f1f
10 changed files with 549 additions and 23 deletions
@@ -11,6 +11,14 @@ vi.mock('./RouteCalculator', async (importActual) => {
const { calculateRouteWithLegs, RoutingRefusedError } = await import('./RouteCalculator')
// Whether the mocked router's answers count as requests that went out. A round paces
// only those; by default the mock answers like the cache, and the pacing tests say otherwise.
const router = vi.hoisted(() => ({ overNetwork: false, asked: 0 }))
vi.mock('./routerAsks', () => ({
routerAnswer: <T>(question: Promise<T>) => question,
routerAsks: () => (router.overNetwork ? ++router.asked : router.asked),
}))
const leg = (distance: number): RouteSegment => ({
mid: [0, 0], from: [0, 0], to: [0, 0], distance, duration: 600,
distanceText: '10 km', durationText: '10 min', walkingText: '2 h', drivingText: '10 min',
@@ -39,6 +47,7 @@ const ASSIGNMENTS: AssignmentsMap = {
const input = { days: DAYS, assignments: ASSIGNMENTS, reservations: [], accommodations: [], optimizeFromAccommodation: false }
beforeEach(() => {
router.overNetwork = false
vi.mocked(calculateRouteWithLegs).mockReset()
vi.mocked(calculateRouteWithLegs).mockResolvedValue({
coordinates: [[48.86, 2.35], [48.90, 2.42]],
@@ -119,6 +128,7 @@ describe('tripRouteGeometry', () => {
it('FE-MAP-TRG-014: a host that never answers costs one leg its road, not the whole round', async () => {
neverAnswers()
router.overNetwork = true
vi.useFakeTimers()
try {
const pending = routeTrip(input, { profile: 'driving', tripId: 7 })
@@ -139,6 +149,7 @@ describe('tripRouteGeometry', () => {
// once is exactly the burst they answer with 429 from the second second on, and each
// refused leg used to stay a straight line with no distance and no word about it.
it('FE-MAP-TRG-007: asks the router one leg at a time, a second apart', async () => {
router.overNetwork = true
vi.useFakeTimers()
try {
// A round trip takes time; only a network answer is paced, a cache hit is not.
@@ -165,6 +176,7 @@ describe('tripRouteGeometry', () => {
})
it('FE-MAP-TRG-008: a rate limit is waited out and the leg asked for again', async () => {
router.overNetwork = true
vi.useFakeTimers()
try {
vi.mocked(calculateRouteWithLegs)
@@ -187,6 +199,7 @@ describe('tripRouteGeometry', () => {
})
it('FE-MAP-TRG-009: a host that says how long to wait is given that long', async () => {
router.overNetwork = true
vi.useFakeTimers()
try {
vi.mocked(calculateRouteWithLegs)