fix: set HTTP client timeout and remove pagination double-fetch
- Set a 30-second default timeout on the shared reqwest client so future call sites can't hang indefinitely. - Use ensure_page_within() to clamp the page before querying instead of fetching, detecting an empty result, and re-fetching.
This commit is contained in:
parent
42b971658d
commit
ca43ad1d00
2 changed files with 11 additions and 19 deletions
|
|
@ -138,7 +138,11 @@ impl AppState {
|
|||
ai_usage_repo,
|
||||
webauthn: config.webauthn,
|
||||
challenge_store: Arc::new(ChallengeStore::new()),
|
||||
http_client: reqwest::Client::new(),
|
||||
#[allow(clippy::expect_used)]
|
||||
http_client: reqwest::ClientBuilder::new()
|
||||
.timeout(std::time::Duration::from_secs(30))
|
||||
.build()
|
||||
.expect("failed to build HTTP client"),
|
||||
foursquare_url: config.foursquare_url,
|
||||
foursquare_api_key: config.foursquare_api_key,
|
||||
openrouter_url: config.openrouter_url,
|
||||
|
|
|
|||
|
|
@ -54,25 +54,14 @@ where
|
|||
}
|
||||
PageSize::Limited(page_size) => {
|
||||
let limit = i64::from(page_size);
|
||||
let mut page = request.page();
|
||||
let offset = i64::from(page - 1).saturating_mul(limit);
|
||||
|
||||
let total = fetch_count(pool, count_query, search).await?;
|
||||
|
||||
let mut records = fetch_records::<R>(
|
||||
pool,
|
||||
base_query,
|
||||
order_clause,
|
||||
search,
|
||||
Some((limit, offset)),
|
||||
)
|
||||
.await?;
|
||||
|
||||
if page > 1 && records.is_empty() && total > 0 {
|
||||
let last_page = ((total + limit - 1) / limit) as u32;
|
||||
page = last_page.max(1);
|
||||
// Clamp page to valid range before fetching
|
||||
let adjusted = (*request).ensure_page_within(total as u64);
|
||||
let page = adjusted.page();
|
||||
let offset = i64::from(page - 1).saturating_mul(limit);
|
||||
records = fetch_records::<R>(
|
||||
|
||||
let records = fetch_records::<R>(
|
||||
pool,
|
||||
base_query,
|
||||
order_clause,
|
||||
|
|
@ -80,7 +69,6 @@ where
|
|||
Some((limit, offset)),
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let mut items = Vec::with_capacity(records.len());
|
||||
for record in records {
|
||||
|
|
|
|||
Loading…
Reference in a new issue