diff --git a/src/history.ts b/src/history.ts index 3effb6f..7f021a4 100644 --- a/src/history.ts +++ b/src/history.ts @@ -73,15 +73,26 @@ export function loadHistory(): PastPlaylist[] { */ const archivable = (t: Track): Track => (t.preview === null ? t : { ...t, preview: null }); +const signatureOf = (tracks: Track[]) => tracks.map((t) => t.id).join(','); + /** * Prepends a playlist to the history, newest first, capped at LIMIT. Pure: the * caller persists the result with saveHistory(). + * + * A playlist identical to the newest entry is not archived again. Pressing + * Generate twice in a row archives the same untouched live playlist each time, + * and a strip of identical entries is worse than no entry. */ export function archivePlaylist( history: PastPlaylist[], seed: string, tracks: Track[], ): PastPlaylist[] { + const newest = history[0]; + if (newest && newest.seed === seed && signatureOf(newest.tracks) === signatureOf(tracks)) { + return history; + } + const entry: PastPlaylist = { id: crypto.randomUUID(), savedAt: Date.now(),