diff --git a/Cargo.lock b/Cargo.lock index ff9fbf82..f1f8e3f9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 4 [[package]] name = "PMOMusic" -version = "0.3.46" +version = "0.3.47" dependencies = [ "axum 0.8.7", "console-subscriber", diff --git a/PMOMusic/Cargo.toml b/PMOMusic/Cargo.toml index 007bf163..32f6d26a 100644 --- a/PMOMusic/Cargo.toml +++ b/PMOMusic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "PMOMusic" -version = "0.3.47" +version = "0.3.48" edition = "2024" [dependencies] diff --git a/pmocache/src/db.rs b/pmocache/src/db.rs index 4bff3632..a7988e99 100644 --- a/pmocache/src/db.rs +++ b/pmocache/src/db.rs @@ -153,33 +153,9 @@ impl DB { }; let conn = Connection::open(path)?; - 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("PRAGMA foreign_keys = ON", [])?; + // 1. CRÉATION DES TABLES EN PREMIER conn.execute( "CREATE TABLE IF NOT EXISTS asset ( pk TEXT PRIMARY KEY, @@ -205,21 +181,30 @@ impl DB { [], )?; - // Créer un index sur la collection pour les requêtes rapides + // 2. Optimisations SQLite pour production + conn.execute_batch( + " + PRAGMA journal_mode = WAL; + PRAGMA synchronous = NORMAL; + PRAGMA cache_size = -32768; + PRAGMA temp_store = MEMORY; + PRAGMA mmap_size = 268435456; + ", + )?; + + // 3. CRÉATION DES INDEX APRÈS LES TABLES conn.execute( "CREATE INDEX IF NOT EXISTS idx_asset_collection ON ASSET (collection)", [], )?; - // Créer un index composite pour optimiser la politique LRU (get_oldest) conn.execute( "CREATE INDEX IF NOT EXISTS idx_asset_lru ON asset (last_used ASC, hits ASC)", [], )?; - // Crée un index composite pour rendre unique les ids si défini dans une collection conn.execute( "CREATE UNIQUE INDEX IF NOT EXISTS asset_collection_id_unique @@ -228,20 +213,32 @@ impl DB { [], )?; - // Index sur metadata(key, value) pour rendre get_pk_by_origin_url efficace. - // Sans cet index, la requête WHERE key = 'origin_url' AND value = ? fait - // un full scan car la PRIMARY KEY est (pk, key). conn.execute( "CREATE INDEX IF NOT EXISTS idx_metadata_key_value ON metadata (key, value)", [], )?; - // LAZY PK SUPPORT: Index sur lazy_pk pour lookups rapides (lazy_pk → real pk) + 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 INDEX IF NOT EXISTS idx_asset_lazy_pk ON asset (lazy_pk)", [], )?; + conn.execute( + "CREATE UNIQUE INDEX IF NOT EXISTS idx_asset_lazy_pk_unique + ON asset (lazy_pk) WHERE lazy_pk IS NOT NULL", + [], + )?; + // Index unique sur lazy_pk (non-NULL) pour éviter les doublons // Un lazy_pk ne peut pointer que vers un seul entry conn.execute( diff --git a/pmocontrol/src/music_renderer/openhome_renderer.rs b/pmocontrol/src/music_renderer/openhome_renderer.rs index bb99efe7..07e06dc9 100644 --- a/pmocontrol/src/music_renderer/openhome_renderer.rs +++ b/pmocontrol/src/music_renderer/openhome_renderer.rs @@ -701,7 +701,7 @@ impl QueueBackend for OpenHomeRenderer { // Background worker: charge les métadonnées petit à petit sans bloquer personne let queue = self.queue.clone(); - tokio::task::spawn_blocking(move || { + std::thread::spawn(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 diff --git a/version.txt b/version.txt index c54101be..2fb885a2 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.3.47 +0.3.48