diff --git a/js/api.js b/js/api.js index 1712072..3186199 100644 --- a/js/api.js +++ b/js/api.js @@ -1182,9 +1182,11 @@ export class LosslessAPI { const results = await Promise.all(artistPromises); results.forEach((tracks) => { - if (tracks.length > 0) { - recommendedTracks.push(...tracks); - tracks.forEach((t) => seenTrackIds.add(t.id)); + for (const t of tracks) { + if (!seenTrackIds.has(t.id)) { + seenTrackIds.add(t.id); + recommendedTracks.push(t); + } } }); diff --git a/js/db.js b/js/db.js index 1924e49..588292f 100644 --- a/js/db.js +++ b/js/db.js @@ -107,20 +107,18 @@ export class MusicDatabase { const store = transaction.objectStore(storeName); const index = store.index('timestamp'); - // Check the most recent entry const cursorReq = index.openCursor(null, 'prev'); cursorReq.onsuccess = (e) => { const cursor = e.target.result; if (cursor) { - const lastTrack = cursor.value; - if (lastTrack.id === track.id) { - // If same track, delete the old entry so we just update the timestamp + if (cursor.value.id === track.id) { store.delete(cursor.primaryKey); } + cursor.continue(); + } else { + store.put(entry); } - // Add the new entry - store.put(entry); }; cursorReq.onerror = (_e) => { diff --git a/js/ui.js b/js/ui.js index 5793b0b..7e3646a 100644 --- a/js/ui.js +++ b/js/ui.js @@ -2187,12 +2187,19 @@ export class UIRenderer { // Take random samples from each to form seeds const shuffle = (arr) => [...arr].sort(() => Math.random() - 0.5); - const seeds = [ + const combined = [ ...shuffle(playlistTracks).slice(0, 20), ...shuffle(favorites).slice(0, 20), ...shuffle(history).slice(0, 10), ]; + const seenIds = new Set(); + const seeds = combined.filter((t) => { + if (seenIds.has(t.id)) return false; + seenIds.add(t.id); + return true; + }); + return shuffle(seeds); }