fix(voice): skip the outline lookup for a sized area around a landmark

A radius the user gives always draws a buffer, but the enclosing outline
was still looked up first (up to 6 s and a guarded Nominatim request) and
then thrown away. It is no longer requested. The slow-outline test now
checks the default 250 m fallback it was meant to cover.
This commit is contained in:
Manjunath committed 2026-11-03 17:55:44 +05:30
1 parent 670e952c29
commit 03e9db07c1
2 files changed
+34 -7

No files matched your search

+10 -5
View File
@@ -603,6 +603,12 @@ export function createVoiceAreas({
return { ok: false, code: 'BAD_AREA', error: 'Name a landmark.' }; return { ok: false, code: 'BAD_AREA', error: 'Name a landmark.' };
const budget = AbortSignal.timeout(AROUND_BUDGET_MS); const budget = AbortSignal.timeout(AROUND_BUDGET_MS);
const combined = signal ? AbortSignal.any([signal, budget]) : budget; const combined = signal ? AbortSignal.any([signal, budget]) : budget;
// A radius the user gave always draws a buffer, so the enclosing outline
// (and its Nominatim request) is never looked up for it.
const explicitRadius =
args.radiusM !== undefined &&
args.radiusM !== null &&
Number.isFinite(Number(args.radiusM));
let resolved; let resolved;
let outline = null; let outline = null;
try { try {
@@ -618,7 +624,10 @@ export function createVoiceAreas({
allowDistant: true, allowDistant: true,
signal: combined, signal: combined,
}); });
outline = resolved ? await awaitOutline(resolved, aroundOutlineMs) : null; outline =
resolved && !explicitRadius
? await awaitOutline(resolved, aroundOutlineMs)
: null;
} catch { } catch {
resolved = null; resolved = null;
} }
@@ -636,10 +645,6 @@ export function createVoiceAreas({
error: `Could not find ${target}.`, error: `Could not find ${target}.`,
}; };
} }
const explicitRadius =
args.radiusM !== undefined &&
args.radiusM !== null &&
Number.isFinite(Number(args.radiusM));
const radiusM = Math.max( const radiusM = Math.max(
50, 50,
Math.min( Math.min(
+24 -2
View File
@@ -588,11 +588,33 @@ test('an area around a landmark uses its enclosing outline, else a labelled buff
const buffered = await slow.areas.resolveAreaAction({ const buffered = await slow.areas.resolveAreaAction({
query: 'Ferry Building', query: 'Ferry Building',
around: true, around: true,
radiusM: 400,
}); });
assert.ok(Date.now() - started < 1000); assert.ok(Date.now() - started < 1000);
assert.equal(buffered.approximate, true); assert.equal(buffered.approximate, true);
assert.equal(buffered.display.basis, '400 m around the landmark'); assert.equal(buffered.display.basis, '250 m around the landmark');
// A radius the user gave never needs the outline, so it is never looked up.
let outlineLookups = 0;
const radius = makeAreas({
annotationResolver: {
resolveAnnotationTarget: async () => ({
lat: 37.7955,
lon: -122.3937,
ring: null,
resolveOutline: async () => {
outlineLookups += 1;
return null;
},
}),
},
});
const sizedBuffer = await radius.areas.resolveAreaAction({
query: 'Ferry Building',
around: true,
radiusM: 400,
});
assert.equal(sizedBuffer.display.basis, '400 m around the landmark');
assert.equal(outlineLookups, 0, 'no outline request for a sized buffer');
const missing = makeAreas({ const missing = makeAreas({
annotationResolver: { resolveAnnotationTarget: async () => null }, annotationResolver: { resolveAnnotationTarget: async () => null },