perf: separate library DB connection for download post-processing

Add a second LibraryDatabase connection to OfflineCacheState dedicated
to download post-processing writes. SQLite WAL mode natively handles
concurrent reads (UI via main connection) and writes (downloads via
this separate connection), eliminating app-level mutex contention that
caused progressive UI lag during bulk downloads.

Init after library.init_at() in both activate_session and
activate_offline_session. Teardown before main offline_cache teardown.
This commit is contained in:
vicrodh committed 2026-02-17 11:02:02 -06:00
1 parent 644571f82a
commit 76cf401a3a
3 files changed
+26 -4

No files matched your search

+2 -4
View File
@@ -6549,7 +6549,6 @@ pub async fn v2_cache_track_for_offline(
sample_rate: Option<f64>,
state: State<'_, AppState>,
cache_state: State<'_, OfflineCacheState>,
library_state: State<'_, crate::library::LibraryState>,
app_handle: tauri::AppHandle,
) -> Result<(), String> {
log::info!("Command: v2_cache_track_for_offline {} - {} by {}", track_id, title, artist);
@@ -6581,7 +6580,7 @@ pub async fn v2_cache_track_for_offline(
cache_state.fetcher.clone(),
cache_state.db.clone(),
cache_state.get_cache_path(),
library_state.db.clone(),
cache_state.library_db.clone(),
app_handle.clone(),
cache_state.cache_semaphore.clone(),
);
@@ -6608,7 +6607,6 @@ pub async fn v2_cache_tracks_batch_for_offline(
tracks: Vec<BatchTrackInfo>,
state: State<'_, AppState>,
cache_state: State<'_, OfflineCacheState>,
library_state: State<'_, crate::library::LibraryState>,
app_handle: tauri::AppHandle,
) -> Result<(), String> {
log::info!("Command: v2_cache_tracks_batch_for_offline ({} tracks)", tracks.len());
@@ -6652,7 +6650,7 @@ pub async fn v2_cache_tracks_batch_for_offline(
cache_state.fetcher.clone(),
cache_state.db.clone(),
cache_state.get_cache_path(),
library_state.db.clone(),
cache_state.library_db.clone(),
app_handle.clone(),
cache_state.cache_semaphore.clone(),
);