MCPcopy Create free account
hub / github.com/acking-you/static_flow / query_fallback_cover

Function query_fallback_cover

crates/cli/src/db.rs:331–401  ·  view source on GitHub ↗

Two-tier fallback for articles without a featured image. Tier 1: images whose filename starts with [`FALLBACK_COVER_PREFIX`]. Tier 2: `featured_image` values from existing articles.

(
    images_table: &Table,
    articles_table: &Table,
)

Source from the content-addressed store, hash-verified

329/// Tier 1: images whose filename starts with [`FALLBACK_COVER_PREFIX`].
330/// Tier 2: `featured_image` values from existing articles.
331pub async fn query_fallback_cover(
332 images_table: &Table,
333 articles_table: &Table,
334) -> Result<Option<String>> {
335 // Tier 1: dedicated fallback covers
336 let filter = format!("filename LIKE '{FALLBACK_COVER_PREFIX}%'");
337 let batches = images_table
338 .query()
339 .only_if(filter)
340 .select(Select::columns(&["id"]))
341 .execute()
342 .await?
343 .try_collect::<Vec<_>>()
344 .await?;
345
346 let mut candidates: Vec<String> = Vec::new();
347 for batch in &batches {
348 if let Some(arr) = batch
349 .column_by_name("id")
350 .and_then(|col| col.as_any().downcast_ref::<StringArray>())
351 {
352 for i in 0..arr.len() {
353 if !arr.is_null(i) {
354 candidates.push(format!("images/{}", arr.value(i)));
355 }
356 }
357 }
358 }
359
360 if !candidates.is_empty() {
361 let pick = pick_random_cover(&candidates);
362 tracing::info!("Fallback cover (dedicated): {pick}");
363 return Ok(Some(pick));
364 }
365
366 // Tier 2: reuse existing article covers
367 let batches = articles_table
368 .query()
369 .only_if("featured_image IS NOT NULL")
370 .select(Select::columns(&["featured_image"]))
371 .execute()
372 .await?
373 .try_collect::<Vec<_>>()
374 .await?;
375
376 let mut candidates: Vec<String> = Vec::new();
377 for batch in &batches {
378 if let Some(arr) = batch
379 .column_by_name("featured_image")
380 .and_then(|col| col.as_any().downcast_ref::<StringArray>())
381 {
382 for i in 0..arr.len() {
383 if !arr.is_null(i) {
384 let val = arr.value(i);
385 if !val.is_empty() {
386 candidates.push(val.to_string());
387 }
388 }

Callers 2

runFunction · 0.85
sync_notesFunction · 0.85

Calls 7

pick_random_coverFunction · 0.85
executeMethod · 0.80
selectMethod · 0.80
queryMethod · 0.80
lenMethod · 0.80
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected