fix: slow thumbnail and analyser test
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -67,7 +67,7 @@ async fn load_thumbnail_config(pool: &sqlx::PgPool) -> ThumbnailConfig {
|
||||
}
|
||||
|
||||
async fn load_thumbnail_concurrency(pool: &sqlx::PgPool) -> usize {
|
||||
let default_concurrency = 4;
|
||||
let default_concurrency = 2;
|
||||
let row = sqlx::query(r#"SELECT value FROM app_settings WHERE key = 'limits'"#)
|
||||
.fetch_optional(pool)
|
||||
.await;
|
||||
@@ -94,11 +94,11 @@ fn generate_thumbnail(image_bytes: &[u8], config: &ThumbnailConfig) -> anyhow::R
|
||||
let ratio = ratio_w.min(ratio_h);
|
||||
let new_w = (orig_w as f32 * ratio) as u32;
|
||||
let new_h = (orig_h as f32 * ratio) as u32;
|
||||
let resized = img.resize(new_w, new_h, image::imageops::FilterType::Lanczos3);
|
||||
let resized = img.resize(new_w, new_h, image::imageops::FilterType::Triangle);
|
||||
let rgba = resized.to_rgba8();
|
||||
let (w, h) = rgba.dimensions();
|
||||
let rgb_data: Vec<u8> = rgba.pixels().flat_map(|p| [p[0], p[1], p[2]]).collect();
|
||||
let quality = f32::max(config.quality as f32, 85.0);
|
||||
let quality = config.quality as f32;
|
||||
let webp_data = webp::Encoder::new(&rgb_data, webp::PixelLayout::Rgb, w, h).encode(quality);
|
||||
Ok(webp_data.to_vec())
|
||||
}
|
||||
|
||||
@@ -200,8 +200,8 @@ fn list_cbr_images(path: &Path) -> Result<Vec<String>> {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
let images: Vec<String> = stdout
|
||||
.lines()
|
||||
.map(|l| l.trim().to_string())
|
||||
.filter(|line| is_image_name(&line.to_ascii_lowercase()))
|
||||
.map(|l| l.to_string())
|
||||
.collect();
|
||||
if !images.is_empty() {
|
||||
return Ok(images);
|
||||
@@ -254,8 +254,8 @@ fn analyze_cbr(path: &Path) -> Result<(i32, Vec<u8>)> {
|
||||
match p_output {
|
||||
Ok(out) if out.status.success() && looks_like_image(&out.stdout) => Ok((count, out.stdout)),
|
||||
_ => {
|
||||
// Fallback: full extraction with unar (handles special chars, encoding issues)
|
||||
let image_bytes = extract_cbr_first_page(path)?;
|
||||
// Fallback: targeted extraction with unar (handles special chars, encoding issues)
|
||||
let image_bytes = extract_cbr_first_page(path, first_name)?;
|
||||
Ok((count, image_bytes))
|
||||
}
|
||||
}
|
||||
@@ -348,7 +348,12 @@ fn is_image_name(name: &str) -> bool {
|
||||
pub fn extract_first_page(path: &Path, format: BookFormat) -> Result<Vec<u8>> {
|
||||
match format {
|
||||
BookFormat::Cbz => extract_cbz_first_page(path),
|
||||
BookFormat::Cbr => extract_cbr_first_page(path),
|
||||
BookFormat::Cbr => {
|
||||
let mut image_names = list_cbr_images(path)?;
|
||||
image_names.sort();
|
||||
let first_name = image_names.into_iter().next().context("no images found in cbr")?;
|
||||
extract_cbr_first_page(path, &first_name)
|
||||
}
|
||||
BookFormat::Pdf => extract_pdf_first_page(path),
|
||||
}
|
||||
}
|
||||
@@ -378,7 +383,7 @@ fn extract_cbz_first_page(path: &Path) -> Result<Vec<u8>> {
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
fn extract_cbr_first_page(path: &Path) -> Result<Vec<u8>> {
|
||||
fn extract_cbr_first_page(path: &Path, first_name: &str) -> Result<Vec<u8>> {
|
||||
let tmp_dir = std::env::temp_dir().join(format!("stripstream-cbr-thumb-{}", Uuid::new_v4()));
|
||||
std::fs::create_dir_all(&tmp_dir).context("cannot create temp dir")?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user