Fix the test and simplify types

This commit is contained in:
Mubelotix 2025-06-23 18:55:23 +02:00
parent 4925b30196
commit 2f82d94502
No known key found for this signature in database
GPG key ID: 89F391DBCC8CE7F0
9 changed files with 87 additions and 51 deletions

View file

@ -31,8 +31,8 @@ pub struct BatchView {
pub struct BatchStatsView {
#[serde(flatten)]
pub stats: BatchStats,
#[serde(skip_serializing_if = "BatchEmbeddingStats::skip_serializing")]
pub embedder: Option<BatchEmbeddingStats>,
#[serde(skip_serializing_if = "BatchEmbeddingStats::skip_serializing", default)]
pub embedder: BatchEmbeddingStats,
}
impl BatchView {

View file

@ -20,7 +20,8 @@ pub struct Batch {
pub progress: Option<ProgressView>,
pub details: DetailsView,
pub stats: BatchStats,
pub embedder_stats: Option<BatchEmbeddingStats>,
#[serde(skip_serializing_if = "BatchEmbeddingStats::skip_serializing", default)]
pub embedder_stats: BatchEmbeddingStats,
#[serde(with = "time::serde::rfc3339")]
pub started_at: OffsetDateTime,
@ -110,10 +111,7 @@ impl From<&EmbedderStats> for BatchEmbeddingStats {
}
impl BatchEmbeddingStats {
pub fn skip_serializing(this: &Option<BatchEmbeddingStats>) -> bool {
match this {
Some(stats) => stats.total_count == 0 && stats.error_count == 0 && stats.last_error.is_none(),
None => true,
}
pub fn skip_serializing(&self) -> bool {
self.total_count == 0 && self.error_count == 0 && self.last_error.is_none()
}
}