Merge pull request #377 from genericness/main
fix(ui): deduplicate recommended songs on homepage
This commit is contained in:
commit
c40cd952a2
3 changed files with 13 additions and 7 deletions
|
|
@ -1182,9 +1182,11 @@ export class LosslessAPI {
|
||||||
|
|
||||||
const results = await Promise.all(artistPromises);
|
const results = await Promise.all(artistPromises);
|
||||||
results.forEach((tracks) => {
|
results.forEach((tracks) => {
|
||||||
if (tracks.length > 0) {
|
for (const t of tracks) {
|
||||||
recommendedTracks.push(...tracks);
|
if (!seenTrackIds.has(t.id)) {
|
||||||
tracks.forEach((t) => seenTrackIds.add(t.id));
|
seenTrackIds.add(t.id);
|
||||||
|
recommendedTracks.push(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
3
js/db.js
3
js/db.js
|
|
@ -107,7 +107,6 @@ export class MusicDatabase {
|
||||||
const store = transaction.objectStore(storeName);
|
const store = transaction.objectStore(storeName);
|
||||||
const index = store.index('timestamp');
|
const index = store.index('timestamp');
|
||||||
|
|
||||||
// Check the most recent entry
|
|
||||||
const cursorReq = index.openCursor(null, 'prev');
|
const cursorReq = index.openCursor(null, 'prev');
|
||||||
|
|
||||||
cursorReq.onsuccess = (e) => {
|
cursorReq.onsuccess = (e) => {
|
||||||
|
|
@ -115,11 +114,9 @@ export class MusicDatabase {
|
||||||
if (cursor) {
|
if (cursor) {
|
||||||
const lastTrack = cursor.value;
|
const lastTrack = cursor.value;
|
||||||
if (lastTrack.id === track.id) {
|
if (lastTrack.id === track.id) {
|
||||||
// If same track, delete the old entry so we just update the timestamp
|
|
||||||
store.delete(cursor.primaryKey);
|
store.delete(cursor.primaryKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Add the new entry
|
|
||||||
store.put(entry);
|
store.put(entry);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
9
js/ui.js
9
js/ui.js
|
|
@ -2187,12 +2187,19 @@ export class UIRenderer {
|
||||||
// Take random samples from each to form seeds
|
// Take random samples from each to form seeds
|
||||||
const shuffle = (arr) => [...arr].sort(() => Math.random() - 0.5);
|
const shuffle = (arr) => [...arr].sort(() => Math.random() - 0.5);
|
||||||
|
|
||||||
const seeds = [
|
const combined = [
|
||||||
...shuffle(playlistTracks).slice(0, 20),
|
...shuffle(playlistTracks).slice(0, 20),
|
||||||
...shuffle(favorites).slice(0, 20),
|
...shuffle(favorites).slice(0, 20),
|
||||||
...shuffle(history).slice(0, 10),
|
...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);
|
return shuffle(seeds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue