fix(suggestions): skip at Qobuz limit, manual launch for large playlists

Playlists at the 2000-track Qobuz limit no longer mount the
suggestions component at all (nothing can be added).

Playlists with >500 tracks require a manual button press to launch
the suggestion engine instead of auto-loading on mount. This avoids
heavy background work that causes UI freezes on large playlists.
This commit is contained in:
vicrodh committed 2026-02-09 20:18:10 -06:00
1 parent 4bbf97a131
commit 02f08e5c8b
4 files changed
+80 -18

No files matched your search

+71 -14
View File
@@ -13,11 +13,14 @@
formatDuration formatDuration
} from '$lib/services/playlistSuggestionsService'; } from '$lib/services/playlistSuggestionsService';
import TrackInfoModal from './TrackInfoModal.svelte'; import TrackInfoModal from './TrackInfoModal.svelte';
import { t } from '$lib/i18n';
interface Props { interface Props {
playlistId: number; playlistId: number;
artists: PlaylistArtist[]; artists: PlaylistArtist[];
excludeTrackIds: number[]; excludeTrackIds: number[];
/** Number of tracks in the playlist (used to gate auto-launch) */
trackCount?: number;
/** Existing tracks in playlist for title+artist deduplication */ /** Existing tracks in playlist for title+artist deduplication */
existingTracks?: Array<{ title: string; artist?: string }>; existingTracks?: Array<{ title: string; artist?: string }>;
/** Callback when track is added - receives full track data for local state update */ /** Callback when track is added - receives full track data for local state update */
@@ -32,6 +35,7 @@
playlistId, playlistId,
artists, artists,
excludeTrackIds, excludeTrackIds,
trackCount = 0,
existingTracks = [], existingTracks = [],
onAddTrack, onAddTrack,
onGoToAlbum, onGoToAlbum,
@@ -40,6 +44,9 @@
showReasons = false showReasons = false
}: Props = $props(); }: Props = $props();
/** Large playlists (>500 tracks) require manual launch */
const MANUAL_LAUNCH_THRESHOLD = 500;
/** /**
* Normalize a string for comparison (lowercase, trim, remove extra whitespace) * Normalize a string for comparison (lowercase, trim, remove extra whitespace)
*/ */
@@ -151,6 +158,7 @@
const canLoadMoreVariety = $derived(hasLoadedOnce && pool.length >= EXPANDED_POOL && pool.length < MAX_POOL && !loadingMore); const canLoadMoreVariety = $derived(hasLoadedOnce && pool.length >= EXPANDED_POOL && pool.length < MAX_POOL && !loadingMore);
const isEmpty = $derived(filteredPool.length === 0 && !loading && hasLoadedOnce); const isEmpty = $derived(filteredPool.length === 0 && !loading && hasLoadedOnce);
const showVarietyPrompt = $derived(completedCycles >= 1 && canLoadMoreVariety); const showVarietyPrompt = $derived(completedCycles >= 1 && canLoadMoreVariety);
const needsManualLaunch = $derived(trackCount > MANUAL_LAUNCH_THRESHOLD && !hasLoadedOnce && !loading);
// Track the last playlist we loaded for // Track the last playlist we loaded for
let lastLoadedPlaylistId = $state<number | null>(null); let lastLoadedPlaylistId = $state<number | null>(null);
@@ -161,20 +169,24 @@
console.log(`[${ts}] [Suggestions]`, ...args); console.log(`[${ts}] [Suggestions]`, ...args);
} }
// Load suggestions when playlist/artists change // Load suggestions when playlist/artists change (auto-launch only for small playlists)
$effect(() => { $effect(() => {
const artistCount = artists.length; const artistCount = artists.length;
const currentPlaylistId = playlistId; const currentPlaylistId = playlistId;
// Only load if we have artists and haven't loaded for this playlist yet // Only load if we have artists and haven't loaded for this playlist yet
if (artistCount > 0 && currentPlaylistId !== lastLoadedPlaylistId && !loading) { if (artistCount > 0 && currentPlaylistId !== lastLoadedPlaylistId && !loading) {
log('Effect triggered, playlist:', currentPlaylistId, 'artists:', artistCount); log('Effect triggered, playlist:', currentPlaylistId, 'artists:', artistCount, 'trackCount:', trackCount);
lastLoadedPlaylistId = currentPlaylistId; lastLoadedPlaylistId = currentPlaylistId;
hasLoadedOnce = false; hasLoadedOnce = false;
pool = []; pool = [];
completedCycles = 0; completedCycles = 0;
lastAddedAt = 0; lastAddedAt = 0;
void loadSuggestions(false);
// Large playlists require manual launch
if (trackCount <= MANUAL_LAUNCH_THRESHOLD) {
void loadSuggestions(false);
}
} }
}); });
@@ -347,25 +359,35 @@
onArtistClick={onGoToArtist} onArtistClick={onGoToArtist}
/> />
{#if artists.length > 0 && !isEmpty} {#if artists.length > 0 && (!isEmpty || needsManualLaunch)}
<div class="suggestions-section" id="suggestions-anchor"> <div class="suggestions-section" id="suggestions-anchor">
<div class="suggestions-header"> <div class="suggestions-header">
<div class="header-left"> <div class="header-left">
<Sparkles size={18} class="sparkle-icon" /> <Sparkles size={18} class="sparkle-icon" />
<h3>Suggested songs</h3> <h3>Suggested songs</h3>
</div> </div>
<button {#if !needsManualLaunch}
class="refresh-btn" <button
class:spinning={loading || loadingMore} class="refresh-btn"
onclick={handleRefresh} class:spinning={loading || loadingMore}
disabled={loading || loadingMore} onclick={handleRefresh}
title={hasMorePages ? 'Show more' : canLoadMore ? 'Load more suggestions' : 'Refresh suggestions'} disabled={loading || loadingMore}
> title={hasMorePages ? 'Show more' : canLoadMore ? 'Load more suggestions' : 'Refresh suggestions'}
<RefreshCw size={16} /> >
</button> <RefreshCw size={16} />
</button>
{/if}
</div> </div>
{#if loading && pool.length === 0} {#if needsManualLaunch}
<div class="manual-launch">
<p class="manual-launch-hint">{$t('playlist.suggestionsLargePlaylist')}</p>
<button class="manual-launch-btn" onclick={() => loadSuggestions(false)}>
<Sparkles size={16} />
{$t('playlist.suggestSongs')}
</button>
</div>
{:else if loading && pool.length === 0}
<div class="loading-state"> <div class="loading-state">
<div class="spinner"></div> <div class="spinner"></div>
<p>Finding similar artists...</p> <p>Finding similar artists...</p>
@@ -800,4 +822,39 @@
border-radius: 50%; border-radius: 50%;
animation: spin 0.6s linear infinite; animation: spin 0.6s linear infinite;
} }
.manual-launch {
display: flex;
flex-direction: column;
align-items: center;
gap: 12px;
padding: 24px 16px;
}
.manual-launch-hint {
font-size: 13px;
color: var(--text-muted);
text-align: center;
margin: 0;
}
.manual-launch-btn {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 20px;
background: var(--bg-tertiary);
border: 1px solid var(--alpha-8);
border-radius: 8px;
color: var(--text-primary);
font-size: 13px;
font-weight: 500;
cursor: pointer;
transition: background 150ms ease, border-color 150ms ease;
}
.manual-launch-btn:hover {
background: var(--alpha-12);
border-color: var(--alpha-20);
}
</style> </style>
@@ -1914,12 +1914,13 @@
{/if} {/if}
</div> </div>
<!-- Playlist Suggestions (only for owned playlists) --> <!-- Playlist Suggestions (only for owned playlists under Qobuz 2000-track limit) -->
{#if playlist && !searchQuery && playlistArtists.length > 0 && isOwnPlaylist} {#if playlist && !searchQuery && playlistArtists.length > 0 && isOwnPlaylist && (playlist.tracks_count ?? 0) < 2000}
<PlaylistSuggestions <PlaylistSuggestions
playlistId={playlistId} playlistId={playlistId}
artists={playlistArtists} artists={playlistArtists}
excludeTrackIds={excludeTrackIds} excludeTrackIds={excludeTrackIds}
trackCount={playlist.tracks_count ?? 0}
existingTracks={tracks.filter(trk => !trk.isLocal).map(trk => ({ title: trk.title, artist: trk.artist }))} existingTracks={tracks.filter(trk => !trk.isLocal).map(trk => ({ title: trk.title, artist: trk.artist }))}
onAddTrack={handleAddSuggestedTrack} onAddTrack={handleAddSuggestedTrack}
onGoToAlbum={onTrackGoToAlbum} onGoToAlbum={onTrackGoToAlbum}
+3 -1
View File
@@ -282,7 +282,9 @@
"addAll": "Add all tracks", "addAll": "Add all tracks",
"addNew": "Add only new tracks", "addNew": "Add only new tracks",
"adding": "Adding..." "adding": "Adding..."
} },
"suggestSongs": "Suggest songs for this playlist",
"suggestionsLargePlaylist": "This playlist has many tracks. Tap the button to generate suggestions."
}, },
"sort": { "sort": {
"nameAZ": "Name (A-Z)", "nameAZ": "Name (A-Z)",
+3 -1
View File
@@ -282,7 +282,9 @@
"addAll": "Agregar todas", "addAll": "Agregar todas",
"addNew": "Agregar solo nuevas", "addNew": "Agregar solo nuevas",
"adding": "Agregando..." "adding": "Agregando..."
} },
"suggestSongs": "Sugerir canciones para esta lista",
"suggestionsLargePlaylist": "Esta lista tiene muchas pistas. Presiona el botón para generar sugerencias."
}, },
"sort": { "sort": {
"nameAZ": "Nombre (A-Z)", "nameAZ": "Nombre (A-Z)",