From 40b5b94102a0edeccfc681b469d919dcce080555 Mon Sep 17 00:00:00 2001 From: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> Date: Wed, 8 Jul 2026 14:06:00 +0300 Subject: [PATCH] fetch historical rates for multiple dates concurrently MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fetchNeededHistoricalRates awaited each date's fetch sequentially even though they're independent requests — a sheet referencing several historical dates paid for that latency serially instead of in parallel. --- src/main.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main.ts b/src/main.ts index a11994a..e3360f8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -568,11 +568,20 @@ const HIST_DATE_RE = /(?:on|на)\s+(\d{4}-\d{2}-\d{2})/gi; async function fetchNeededHistoricalRates(text: string): Promise { const dates = new Set(); for (const m of text.matchAll(HIST_DATE_RE)) dates.add(m[1]!); + const datesToFetch = Array.from(dates).filter((date) => !engine.hasHistoricalRates(date)); let fetched = false; - for (const date of dates) { - if (!engine.hasHistoricalRates(date)) { - const rates = await fetchHistoricalRates(date); - if (rates) { engine.setHistoricalRates(date, rates); fetched = true; } + if (datesToFetch.length > 0) { + const results = await Promise.all( + datesToFetch.map(async (date) => { + const rates = await fetchHistoricalRates(date); + return { date, rates }; + }) + ); + for (const { date, rates } of results) { + if (rates) { + engine.setHistoricalRates(date, rates); + fetched = true; + } } } if (fetched) { workspace.invalidateAll(); editor.refresh(); }