mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 01:02:01 +03:00
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:
parent
9849d6552a
commit
cb437f5a74
1 changed files with 2 additions and 2 deletions
|
|
@ -431,7 +431,6 @@ async fn fetch_historical_rates(
|
|||
Ok(rates)
|
||||
}
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
async fn fetch_historical_rates_batch(
|
||||
app: AppHandle,
|
||||
|
|
@ -446,7 +445,8 @@ async fn fetch_historical_rates_batch(
|
|||
}
|
||||
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(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);
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue