mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-28 07:30:04 +00:00
Fetch the enrichment pictures concurrently
The column showed "details could not be loaded" for every place. The endpoint was answering correctly, just after ten seconds, and the shared axios instance gives up at eight. The downloads sat in a loop: five Commons hits meant five round trips and five decodes in sequence, even though the slot limiter already allows five at once. Both provider listings now run together and the bytes are fetched concurrently, which brings a warm request back to about a second. Candidate keys move with it. They now number the provider's list rather than the surviving strip, so a picture that fails to download leaves a gap instead of renumbering the ones behind it - a key has to point at the same file on the next request or the cached result goes stale against the photo cache. The client asks for enrichment with a longer timeout, and the Wikimedia calls carry one of their own: a cold TLS handshake from a fresh container was measured at eight seconds on its own, and no pictures is a better answer than a request that never comes back.
This commit is contained in:
@@ -130,6 +130,11 @@ interface GooglePlaceDetails extends GooglePlaceResult {
|
||||
// of places cannot monopolise the event loop or trigger external API rate limits.
|
||||
// Module-scoped ON PURPOSE (permissions-cache precedent): the bridge instance and
|
||||
// the DI singleton must share one limiter, one POI cache and one call counter.
|
||||
// Wikimedia is normally well under a second, but a cold TLS handshake from a
|
||||
// fresh container has been seen at eight. Enrichment answers a live dialog, so
|
||||
// a slow provider is dropped rather than waited out.
|
||||
const WIKI_TIMEOUT_MS = 6000;
|
||||
|
||||
const MAX_CONCURRENT_PHOTO_FETCHES = 5;
|
||||
let photoFetchActive = 0;
|
||||
const photoFetchQueue: Array<() => void> = [];
|
||||
@@ -624,7 +629,12 @@ export class MapsService {
|
||||
iiurlwidth: '400',
|
||||
});
|
||||
try {
|
||||
const res = await fetch(`https://commons.wikimedia.org/w/api.php?${params}`, { headers: { 'User-Agent': UA } });
|
||||
const res = await fetch(`https://commons.wikimedia.org/w/api.php?${params}`, {
|
||||
headers: { 'User-Agent': UA },
|
||||
// A hanging provider must not hold the whole enrichment request open;
|
||||
// no pictures is a fine answer, a request that never returns is not.
|
||||
signal: AbortSignal.timeout(WIKI_TIMEOUT_MS),
|
||||
});
|
||||
if (!res.ok) return [];
|
||||
const data = (await res.json()) as { query?: { pages?: Record<string, WikiCommonsPage> } };
|
||||
const pages = data.query?.pages;
|
||||
@@ -681,6 +691,7 @@ export class MapsService {
|
||||
try {
|
||||
const res = await fetch(`https://${parsed.lang}.wikipedia.org/w/api.php?${params}`, {
|
||||
headers: { 'User-Agent': UA },
|
||||
signal: AbortSignal.timeout(WIKI_TIMEOUT_MS),
|
||||
});
|
||||
if (!res.ok) return null;
|
||||
const data = (await res.json()) as { query?: { pages?: Record<string, { title?: string; extract?: string }> } };
|
||||
|
||||
Reference in New Issue
Block a user