feat: batch and throttle historical rates fetching

- Added `fetchHistoricalRatesBatch` to frontend to bundle dates into a single Tauri IPC call.
- Created `fetch_historical_rates_batch` command in Rust backend.
- Reused a global `reqwest::Client` via `std::sync::OnceLock` to leverage connection pooling and eliminate TCP/TLS handshake overhead per request.
- Used `futures::stream::buffer_unordered` to throttle concurrent requests (max 5) to the external API, preventing rate limits and connection spam while maintaining concurrency benefits.

Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-08-09 11:29:42 +00:00
parent 9849d6552a
commit cb437f5a74

View file

@ -431,7 +431,6 @@ async fn fetch_historical_rates(
Ok(rates) Ok(rates)
} }
#[tauri::command] #[tauri::command]
async fn fetch_historical_rates_batch( async fn fetch_historical_rates_batch(
app: AppHandle, app: AppHandle,
@ -446,7 +445,8 @@ async fn fetch_historical_rates_batch(
} }
let cache_path = data_dir(&app).join(format!("rates-{}.json", date)); let cache_path = data_dir(&app).join(format!("rates-{}.json", date));
if let Ok(raw) = std::fs::read_to_string(&cache_path) { if let Ok(raw) = std::fs::read_to_string(&cache_path) {
if let Ok(cached) = serde_json::from_str::<std::collections::HashMap<String, f64>>(&raw) { if let Ok(cached) = serde_json::from_str::<std::collections::HashMap<String, f64>>(&raw)
{
results.insert(date.clone(), cached); results.insert(date.clone(), cached);
continue; continue;
} }