refactor(v2): inline library scan progress, stats, and search delegates
Inlines bodies of library_get_scan_progress, library_get_artists, library_search, and library_get_stats from library/commands.rs directly into the v2 wrappers in commands_v2/library.rs. Deletes the corresponding legacy #[tauri::command] definitions and removes their re-exports from library/mod.rs. Step 8 of legacy cleanup, group C. cc
This commit is contained in:
3 files changed
+79
-127
No files matched your search
@@ -779,7 +779,8 @@ pub async fn v2_library_get_thumbnails_cache_size() -> Result<u64, String> {
|
||||
pub async fn v2_library_get_scan_progress(
|
||||
library_state: State<'_, LibraryState>,
|
||||
) -> Result<ScanProgress, String> {
|
||||
crate::library::library_get_scan_progress(library_state).await
|
||||
let progress = library_state.scan_progress.lock().await;
|
||||
Ok(progress.clone())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -2056,7 +2057,21 @@ pub async fn v2_library_get_stats(
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, DownloadSettingsState>,
|
||||
) -> Result<crate::library::LibraryStats, String> {
|
||||
crate::library::library_get_stats(state, download_settings_state).await
|
||||
log::info!("Command: library_get_stats");
|
||||
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
db.get_stats(include_qobuz).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -2252,8 +2267,32 @@ pub async fn v2_library_get_artists(
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, DownloadSettingsState>,
|
||||
) -> Result<Vec<crate::library::LocalArtist>, String> {
|
||||
crate::library::library_get_artists(exclude_network_folders, state, download_settings_state)
|
||||
.await
|
||||
log::info!(
|
||||
"Command: library_get_artists (exclude_network: {:?})",
|
||||
exclude_network_folders
|
||||
);
|
||||
|
||||
// Get download settings
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
|
||||
// Use optimized SQL-based filtering instead of N+1 query pattern
|
||||
let artists = db
|
||||
.get_artists_with_filter(include_qobuz, exclude_network_folders.unwrap_or(false))
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
log::info!("Returning {} artists", artists.len());
|
||||
Ok(artists)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -2264,14 +2303,39 @@ pub async fn v2_library_search(
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, DownloadSettingsState>,
|
||||
) -> Result<Vec<crate::library::LocalTrack>, String> {
|
||||
crate::library::library_search(
|
||||
log::info!(
|
||||
"Command: library_search \"{}\" (exclude_network: {:?})",
|
||||
query,
|
||||
limit,
|
||||
exclude_network_folders,
|
||||
state,
|
||||
download_settings_state,
|
||||
exclude_network_folders
|
||||
);
|
||||
|
||||
// Get download settings
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
|
||||
// Use optimized SQL-based filtering
|
||||
// limit = 0 means no limit (fetch all tracks)
|
||||
let tracks = db
|
||||
.search_with_filter(
|
||||
&query,
|
||||
limit.unwrap_or(0),
|
||||
include_qobuz,
|
||||
exclude_network_folders.unwrap_or(false),
|
||||
)
|
||||
.await
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
log::info!("Search returned {} tracks", tracks.len());
|
||||
Ok(tracks)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -6,8 +6,8 @@ use tauri::State;
|
||||
|
||||
use crate::discogs::DiscogsClient;
|
||||
use crate::library::{
|
||||
get_artwork_cache_dir, thumbnails, ArtistImageInfo, LibraryFolder, LibraryStats, LocalAlbum,
|
||||
LocalArtist, LocalTrack, MetadataExtractor, ScanProgress,
|
||||
get_artwork_cache_dir, thumbnails, ArtistImageInfo, LibraryFolder, LocalAlbum, LocalTrack,
|
||||
MetadataExtractor,
|
||||
};
|
||||
|
||||
// Shared state types and DTOs live in `super::state`; re-export them from
|
||||
@@ -267,17 +267,6 @@ pub async fn library_check_folder_accessible(path: String) -> Result<bool, Strin
|
||||
}
|
||||
}
|
||||
|
||||
// === Scanning ===
|
||||
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn library_get_scan_progress(
|
||||
state: State<'_, LibraryState>,
|
||||
) -> Result<ScanProgress, String> {
|
||||
let progress = state.scan_progress.lock().await;
|
||||
Ok(progress.clone())
|
||||
}
|
||||
|
||||
// === Queries ===
|
||||
|
||||
#[tauri::command]
|
||||
@@ -334,105 +323,6 @@ pub async fn library_get_album_tracks(
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn library_get_artists(
|
||||
exclude_network_folders: Option<bool>,
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, crate::config::DownloadSettingsState>,
|
||||
) -> Result<Vec<LocalArtist>, String> {
|
||||
log::info!(
|
||||
"Command: library_get_artists (exclude_network: {:?})",
|
||||
exclude_network_folders
|
||||
);
|
||||
|
||||
// Get download settings
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
|
||||
// Use optimized SQL-based filtering instead of N+1 query pattern
|
||||
let artists = db
|
||||
.get_artists_with_filter(include_qobuz, exclude_network_folders.unwrap_or(false))
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
log::info!("Returning {} artists", artists.len());
|
||||
Ok(artists)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn library_search(
|
||||
query: String,
|
||||
limit: Option<u32>,
|
||||
exclude_network_folders: Option<bool>,
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, crate::config::DownloadSettingsState>,
|
||||
) -> Result<Vec<LocalTrack>, String> {
|
||||
log::info!(
|
||||
"Command: library_search \"{}\" (exclude_network: {:?})",
|
||||
query,
|
||||
exclude_network_folders
|
||||
);
|
||||
|
||||
// Get download settings
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
|
||||
// Use optimized SQL-based filtering
|
||||
// limit = 0 means no limit (fetch all tracks)
|
||||
let tracks = db
|
||||
.search_with_filter(
|
||||
&query,
|
||||
limit.unwrap_or(0),
|
||||
include_qobuz,
|
||||
exclude_network_folders.unwrap_or(false),
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
log::info!("Search returned {} tracks", tracks.len());
|
||||
Ok(tracks)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn library_get_stats(
|
||||
state: State<'_, LibraryState>,
|
||||
download_settings_state: State<'_, crate::config::DownloadSettingsState>,
|
||||
) -> Result<LibraryStats, String> {
|
||||
log::info!("Command: library_get_stats");
|
||||
|
||||
let include_qobuz = download_settings_state
|
||||
.lock()
|
||||
.map_err(|e| format!("Failed to lock download settings: {}", e))?
|
||||
.as_ref()
|
||||
.and_then(|s| s.get_settings().ok())
|
||||
.map(|s| s.show_in_library)
|
||||
.unwrap_or(false);
|
||||
|
||||
let guard__ = state.db.lock().await;
|
||||
let db = guard__
|
||||
.as_ref()
|
||||
.ok_or("No active session - please log in")?;
|
||||
db.get_stats(include_qobuz).map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
// === Playback ===
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
@@ -86,11 +86,9 @@ pub use state::{
|
||||
LibraryAlbumTrackMetadataUpdate, LibraryState,
|
||||
};
|
||||
pub use commands::{
|
||||
library_fetch_missing_artwork, library_get_album_tracks, library_get_artists,
|
||||
library_get_scan_progress, library_get_stats, library_get_thumbnail,
|
||||
library_get_thumbnails_cache_size, library_get_tracks_by_ids, library_search,
|
||||
playlist_get_custom_order, playlist_get_tracks_with_local_copies, playlist_has_custom_order,
|
||||
update_playlist_folder,
|
||||
library_fetch_missing_artwork, library_get_album_tracks, library_get_thumbnail,
|
||||
library_get_thumbnails_cache_size, library_get_tracks_by_ids, playlist_get_custom_order,
|
||||
playlist_get_tracks_with_local_copies, playlist_has_custom_order, update_playlist_folder,
|
||||
};
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
Reference in new issue
Block a user