From f988ebf5f5668ff4c3ed1b2842e4b6ab4a756fb4 Mon Sep 17 00:00:00 2001 From: Broque Thomas Date: Mon, 16 Feb 2026 13:50:03 -0800 Subject: [PATCH] fixed an issue where backend and front could be out of sync on wishlist modal --- web_server.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/web_server.py b/web_server.py index e1f7bb27..e01f5a1a 100644 --- a/web_server.py +++ b/web_server.py @@ -10971,18 +10971,24 @@ def start_wishlist_missing_downloads(): # FILTER BY TRACK IDs if specified (prioritized - prevents race conditions) if track_ids: - # Convert to set for O(1) lookup - track_id_set = set(track_ids) - filtered_tracks = [] - seen_track_ids = set() # Track IDs we've already added to prevent duplicates + # Build a lookup by track ID for O(1) access + track_lookup = {} for track in wishlist_tracks: spotify_track_id = track.get('spotify_track_id') or track.get('id') - if spotify_track_id in track_id_set and spotify_track_id not in seen_track_ids: - filtered_tracks.append(track) - seen_track_ids.add(spotify_track_id) + if spotify_track_id and spotify_track_id not in track_lookup: + track_lookup[spotify_track_id] = track + + # Iterate in track_ids order (matches frontend display order) + # so that enumerate()-based track_index aligns with data-track-index in the modal + filtered_tracks = [] + seen_track_ids = set() + for tid in track_ids: + if tid in track_lookup and tid not in seen_track_ids: + filtered_tracks.append(track_lookup[tid]) + seen_track_ids.add(tid) wishlist_tracks = filtered_tracks - print(f"🎯 [Manual-Wishlist] Filtered to {len(wishlist_tracks)} specific tracks by ID (preventing race condition)") + print(f"🎯 [Manual-Wishlist] Filtered to {len(wishlist_tracks)} specific tracks by ID (preserving frontend display order)") # FILTER BY CATEGORY if specified and no track_ids (backward compatibility) elif category: