diff --git a/api/_lib/researchSources.ts b/api/_lib/researchSources.ts index 3c2d352..d38f6ce 100644 --- a/api/_lib/researchSources.ts +++ b/api/_lib/researchSources.ts @@ -47,14 +47,24 @@ const MAX_ARTICLES = 24 const FETCH_CONCURRENCY = 8 const FETCH_TIMEOUT_MS = 15_000 + +/** + * Eigenes Zeitlimit für die Zefix-CSV. + * + * Die Datei ist 10,5 MB gross und wird unkomprimiert ausgeliefert — der Server + * bietet kein gzip an. Von einem Schweizer Anschluss dauert der Abruf keine + * zwei Sekunden, aus dem Rechenzentrum der Anwendung aber mehr als fünfzehn, + * und genau daran ist die Quelle im ersten Produktionslauf gescheitert. + */ +const CSV_TIMEOUT_MS = 30_000 const UA = 'Mozilla/5.0 (compatible; PropertyMatch-LiviaResearch/1.0; +https://property-match-virid.vercel.app)' -async function getText(url: string, extraHeaders: Record = {}): Promise { +async function getText(url: string, timeoutMs: number = FETCH_TIMEOUT_MS): Promise { const ctrl = new AbortController() - const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS) + const timer = setTimeout(() => ctrl.abort(), timeoutMs) try { const res = await fetch(url, { - headers: { 'User-Agent': UA, 'Accept-Language': 'de-CH,de;q=0.9', ...extraHeaders }, + headers: { 'User-Agent': UA, 'Accept-Language': 'de-CH,de;q=0.9' }, redirect: 'follow', signal: ctrl.signal, }) @@ -257,7 +267,7 @@ export async function fetchGreaterZurichResearch(): Promise { * Sache, die Livia nie tun darf. */ export async function fetchZefixResearch(): Promise { - const csv = await getText(SOURCES.ZEFIX.url) + const csv = await getText(SOURCES.ZEFIX.url, CSV_TIMEOUT_MS) const lines = csv.split(/\r?\n/) if (lines.length < 2) throw new Error('CSV enthält keine Daten')