diff --git a/scraper-rs/src/best_selling.rs b/scraper-rs/src/best_selling.rs index 420d087..d844eb1 100644 --- a/scraper-rs/src/best_selling.rs +++ b/scraper-rs/src/best_selling.rs @@ -120,18 +120,22 @@ pub async fn get_all_best_selling(db: &Db) -> anyhow::Result>>() .map(|r| { let ranked = rank_eans(r); - BestSellingRecord { + if ranked.is_empty() { + return None; + } + Some(BestSellingRecord { fetched_at: Utc::now(), category: category.clone(), eans: ranked, - } + }) }) }) .buffer_unordered(5) .boxed() + .filter_map(|f| async { f }) .collect::>() .await; - if records.len() < 10 { + if records.len() < Category::value_variants().len() { Err(SimpleError::new("Too few BestSellingRecords").into()) } else { Ok(records)