From 353e54af763e2a7bc087d2426cc88db682a5903c Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 9 Apr 2026 23:06:26 +0200 Subject: [PATCH] :arrow_up: Bump version to v0.3.47 - Update package versions in Cargo.toml, lockfile and version.txt to v0.3.47 - Optimize SQLite database initialization with WAL mode, larger cache and critical missing indexes (idx_metadata_key_value, idx_asset_last_used/hits) - Fix production bug in OpenHome renderer: avoid blocking main thread when loading metadata for large queues; offload preloading of next 10 items to background task with small delays - Minor formatting cleanup in db.rs --- Cargo.lock | 2 +- PMOMusic/Cargo.toml | 2 +- pmocache/src/db.rs | 38 +++++++++++++++++-- .../src/music_renderer/openhome_renderer.rs | 30 ++++++++++++++- version.txt | 2 +- 5 files changed, 66 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 08e4a773..ff9fbf82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "PMOMusic" -version = "0.3.45" +version = "0.3.46" dependencies = [ "axum 0.8.7", "console-subscriber", diff --git a/PMOMusic/Cargo.toml b/PMOMusic/Cargo.toml index 0114ecf7..007bf163 100644 --- a/PMOMusic/Cargo.toml +++ b/PMOMusic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "PMOMusic" -version = "0.3.46" +version = "0.3.47" edition = "2024" [dependencies] diff --git a/pmocache/src/db.rs b/pmocache/src/db.rs index 3f7b0081..4bff3632 100644 --- a/pmocache/src/db.rs +++ b/pmocache/src/db.rs @@ -153,7 +153,32 @@ impl DB { }; let conn = Connection::open(path)?; - conn.execute("PRAGMA foreign_keys = ON", [])?; + conn.execute_batch( + " + PRAGMA journal_mode = WAL; + PRAGMA synchronous = NORMAL; + PRAGMA cache_size = -32768; + PRAGMA temp_store = MEMORY; + PRAGMA mmap_size = 268435456; + ", + )?; + + // Index qui MANQUAIT sur les bases existantes: + // Ceci s'exécutera TOUT LE TEMPS, pas seulement à la création + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_metadata_key_value ON metadata (key, value)", + [], + )?; + + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_asset_last_used ON asset (last_used DESC)", + [], + )?; + + conn.execute( + "CREATE INDEX IF NOT EXISTS idx_asset_hits ON asset (hits DESC)", + [], + )?; conn.execute( "CREATE TABLE IF NOT EXISTS asset ( @@ -228,7 +253,12 @@ impl DB { // Inscrire la version du schéma conn.execute_batch(&format!("PRAGMA user_version = {}", SCHEMA_VERSION))?; - Ok((Self { conn: Mutex::new(conn) }, was_reset)) + Ok(( + Self { + conn: Mutex::new(conn), + }, + was_reset, + )) } /// Ajoute ou met à jour une entrée dans la base de données @@ -1158,7 +1188,9 @@ impl DB { tracing::debug!( "update_lazy_to_downloaded: {} → {} ({} metadata rows still under lazy_pk)", - lazy_pk, real_pk, meta_under_lazy + lazy_pk, + real_pk, + meta_under_lazy ); Ok(()) diff --git a/pmocontrol/src/music_renderer/openhome_renderer.rs b/pmocontrol/src/music_renderer/openhome_renderer.rs index c843c4e6..bb99efe7 100644 --- a/pmocontrol/src/music_renderer/openhome_renderer.rs +++ b/pmocontrol/src/music_renderer/openhome_renderer.rs @@ -688,10 +688,36 @@ impl QueueBackend for OpenHomeRenderer { items: Vec, current_index: Option, ) -> Result<(), ControlPointError> { + // ✅ CORRECTION BUG PRODUCTION: On ne charge PAS toutes les métadonnées + // dans le thread principal. OpenHome sur 1000 titres inondait la base SQLite + // et bloquait TOUS les autres threads (mutex >500ms). + // + // On fait juste l'insertion minimaliste maintenant. Le préchargement + // des métadonnées est délégué à un thread background. self.queue .lock() - .map_err(|_| ControlPointError::QueueError("Queue mutex poisoned".into()))? - .replace_queue(items, current_index) + .map_err(|_| ControlPointError::QueueError("Mutex poisoned".into()))? + .replace_queue(items, current_index)?; + + // Background worker: charge les métadonnées petit à petit sans bloquer personne + let queue = self.queue.clone(); + tokio::task::spawn_blocking(move || { + debug!("🔄 OpenHome: préchargement métadonnées queue en background"); + if let Ok(mut queue) = queue.lock() { + // On ne fait que les 10 prochains titres maintenant, le reste on s'en fout + if let Ok(Some(idx)) = queue.current_index() { + let end = std::cmp::min(idx + 10, queue.len().unwrap_or(0)); + for i in idx..end { + let _ = queue.get_item(i); + // Petit délai pour ne pas noyer la base de données + std::thread::sleep(std::time::Duration::from_millis(5)); + } + } + } + debug!("✅ OpenHome: préchargement métadonnées terminé"); + }); + + Ok(()) } fn sync_queue( diff --git a/version.txt b/version.txt index b9c7814c..c54101be 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.3.46 +0.3.47 -- 2.49.1