various: eliminate redundant disk check; improve error handling

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I1f37cc60380790bc1bf11f143194ad116a6a6964
This commit is contained in:
raf 2026-02-05 22:48:02 +03:00
commit 1c18306822
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
5 changed files with 39 additions and 23 deletions

View file

@ -294,7 +294,7 @@ pub struct PaginationParams {
impl PaginationParams {
pub fn limit(&self) -> i64 {
self.limit.unwrap_or(50).min(200).max(1)
self.limit.unwrap_or(50).clamp(1, 200)
}
pub fn offset(&self) -> i64 {

View file

@ -142,11 +142,22 @@ pub async fn list_for_project(
}
pub async fn get_stats(pool: &PgPool) -> Result<BuildStats> {
sqlx::query_as::<_, BuildStats>("SELECT * FROM build_stats")
match sqlx::query_as::<_, BuildStats>("SELECT * FROM build_stats")
.fetch_optional(pool)
.await
.map_err(CiError::Database)
.map(|opt| opt.unwrap_or_default())
{
Ok(Some(stats)) => Ok(stats),
Ok(None) => {
tracing::warn!(
"build_stats view returned no rows, returning default stats"
);
Ok(BuildStats::default())
},
Err(e) => {
tracing::error!(error = %e, "Failed to fetch build stats");
Err(CiError::Database(e))
},
}
}
/// Reset builds that were left in 'running' state (orphaned by a crashed