fix(ui): deduplicate recommended songs on homepage
This commit is contained in:
parent
da5ade79a7
commit
446b6fff55
3 changed files with 17 additions and 10 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
10
js/db.js
10
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) => {
|
||||
|
|
|
|||
9
js/ui.js
9
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue