feat(playlist-import): concurrent matching with progress reporting

Replace sequential track matching with buffer_unordered(8) for 8
concurrent Qobuz API calls, reducing import time ~8x. Add real-time
progress events (import:progress, import:phase) emitted from Rust
backend and consumed by frontend via Tauri event listeners.

Frontend shows progress bar, matching status text, and current track
name during import. Individual search failures are now logged and
skipped instead of aborting the entire import.
This commit is contained in:
vicrodh committed 2026-02-09 17:53:04 -06:00
1 parent a46a422a04
commit 9fdd1dd0df
10 files changed
+278 -37

No files matched your search

+107 -1
View File
@@ -1,5 +1,6 @@
<script lang="ts">
import { invoke } from '@tauri-apps/api/core';
import { listen, type UnlistenFn } from '@tauri-apps/api/event';
import { X, CloudOff } from 'lucide-svelte';
import { showToast } from '$lib/stores/toastStore';
import { t } from '$lib/i18n';
@@ -57,6 +58,8 @@
let isOffline = $state(checkIsOffline());
let importCompleted = $state(false);
let lastImportedUrl = $state('');
let importProgress = $state<{ phase: string; current: number; total: number; matched_so_far: number; current_track: string | null } | null>(null);
let importPhase = $state<string | null>(null);
// Preview + customization state
let preview = $state<ImportPlaylist | null>(null);
@@ -106,6 +109,8 @@
logEntries = [];
importCompleted = false;
lastImportedUrl = '';
importProgress = null;
importPhase = null;
preview = null;
previewUrl = '';
customName = '';
@@ -187,9 +192,57 @@
loading = true;
error = null;
importProgress = null;
importPhase = null;
let unlistenProgress: UnlistenFn | null = null;
let unlistenPhase: UnlistenFn | null = null;
let lastLoggedPercent = -1;
try {
pushLog('Matching tracks in Qobuz\u2122...');
// Set up event listeners before invoking
unlistenProgress = await listen<{ phase: string; current: number; total: number; matched_so_far: number; current_track: string | null }>('import:progress', (event) => {
importProgress = event.payload;
if (event.payload.phase === 'matching' && event.payload.total > 0) {
const pct = Math.floor((event.payload.current / event.payload.total) * 100);
// Log at every 5% milestone
if (pct >= lastLoggedPercent + 5) {
lastLoggedPercent = pct;
pushLog(
$t('playlistImport.matchingTracks', {
values: {
current: event.payload.current.toLocaleString(),
total: event.payload.total.toLocaleString(),
matched: event.payload.matched_so_far.toLocaleString()
}
})
);
}
} else if (event.payload.phase === 'adding') {
pushLog(
$t('playlistImport.addingProgress', {
values: {
current: event.payload.current,
total: event.payload.total
}
})
);
}
});
unlistenPhase = await listen<{ phase: string }>('import:phase', (event) => {
importPhase = event.payload.phase;
if (event.payload.phase === 'matching') {
pushLog($t('playlistImport.matchingPhase'));
} else if (event.payload.phase === 'creating') {
pushLog($t('playlistImport.creatingPhase'), 'success');
} else if (event.payload.phase === 'adding') {
pushLog($t('playlistImport.addingPhase'));
}
});
const nameOverride = customName.trim() !== preview.name ? customName.trim() || null : null;
const result = await invoke<ImportSummary>('playlist_import_execute', {
url: previewUrl,
@@ -223,6 +276,8 @@
showToast($t('toast.playlistImportFailed'), 'error');
} finally {
loading = false;
unlistenProgress?.();
unlistenPhase?.();
}
}
@@ -352,6 +407,26 @@
<span class="spinner" aria-hidden="true"></span>
{/if}
</div>
{#if importProgress && importProgress.total > 0 && loading}
<div class="progress-bar-container">
<div
class="progress-bar-fill"
style="width: {Math.min(100, (importProgress.current / importProgress.total) * 100)}%"
></div>
</div>
<div class="progress-status">
{$t('playlistImport.matchingTracks', {
values: {
current: importProgress.current.toLocaleString(),
total: importProgress.total.toLocaleString(),
matched: importProgress.matched_so_far.toLocaleString()
}
})}
</div>
{#if importProgress.current_track}
<div class="progress-current-track">{importProgress.current_track}</div>
{/if}
{/if}
<ul class="progress-log">
{#each logEntries as entry}
<li class={`log-item ${entry.status}`}>{entry.message}</li>
@@ -605,6 +680,37 @@
margin-bottom: 10px;
}
.progress-bar-container {
width: 100%;
height: 6px;
background: var(--alpha-8);
border-radius: 3px;
overflow: hidden;
margin-bottom: 8px;
}
.progress-bar-fill {
height: 100%;
background: var(--accent-primary);
border-radius: 3px;
transition: width 200ms ease;
}
.progress-status {
font-size: 12px;
color: var(--text-secondary);
margin-bottom: 4px;
}
.progress-current-track {
font-size: 11px;
color: var(--text-muted);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
margin-bottom: 10px;
}
.progress-log {
list-style: none;
padding: 0;
+6 -1
View File
@@ -1318,6 +1318,11 @@
"summary": "Zusammenfassung",
"playlistLabel": "Playlist: {name}",
"tracksMatched": "Titel zugeordnet: {matched} / {total}",
"skipped": "Übersprungen: {count}"
"skipped": "Übersprungen: {count}",
"matchingTracks": "Titel abgleichen: {current} / {total} ({matched} gefunden)",
"matchingPhase": "Qobuz-Katalog durchsuchen...",
"creatingPhase": "Playlist erstellen...",
"addingPhase": "Titel zur Playlist hinzufugen...",
"addingProgress": "Titel hinzufugen: {current} / {total}"
}
}
+6 -1
View File
@@ -1520,6 +1520,11 @@
"summary": "Summary",
"playlistLabel": "Playlist: {name}",
"tracksMatched": "Tracks matched: {matched} / {total}",
"skipped": "Skipped: {count}"
"skipped": "Skipped: {count}",
"matchingTracks": "Matching tracks: {current} / {total} ({matched} found)",
"matchingPhase": "Searching Qobuz catalog...",
"creatingPhase": "Creating playlist...",
"addingPhase": "Adding tracks to playlist...",
"addingProgress": "Adding tracks: {current} / {total}"
}
}
+6 -1
View File
@@ -1520,6 +1520,11 @@
"summary": "Resumen",
"playlistLabel": "Playlist: {name}",
"tracksMatched": "Tracks encontrados: {matched} / {total}",
"skipped": "Omitidos: {count}"
"skipped": "Omitidos: {count}",
"matchingTracks": "Buscando tracks: {current} / {total} ({matched} encontrados)",
"matchingPhase": "Buscando en el catalogo de Qobuz...",
"creatingPhase": "Creando playlist...",
"addingPhase": "Agregando tracks a la playlist...",
"addingProgress": "Agregando tracks: {current} / {total}"
}
}
+6 -1
View File
@@ -1318,6 +1318,11 @@
"summary": "Resume",
"playlistLabel": "Playlist : {name}",
"tracksMatched": "Titres trouves : {matched} / {total}",
"skipped": "Ignores : {count}"
"skipped": "Ignores : {count}",
"matchingTracks": "Recherche des titres : {current} / {total} ({matched} trouves)",
"matchingPhase": "Recherche dans le catalogue Qobuz...",
"creatingPhase": "Creation de la playlist...",
"addingPhase": "Ajout des titres a la playlist...",
"addingProgress": "Ajout des titres : {current} / {total}"
}
}