Fix manual mappings: preserve on rematch + fix local/external count detection

This commit is contained in:
2026-02-04 18:53:09 -05:00
parent 5680b9c7c9
commit 696a2d56f2
2 changed files with 32 additions and 5 deletions

View File

@@ -262,14 +262,21 @@ public class AdminController : ControllerBase
foreach (var item in cachedPlaylistItems) foreach (var item in cachedPlaylistItems)
{ {
// Check if it's a local track (has Path) or external (no Path) // Check if it's external by looking for ProviderIds (external songs have this)
if (item.TryGetValue("Path", out var pathObj) && pathObj != null) var isExternal = false;
if (item.TryGetValue("ProviderIds", out var providerIdsObj) && providerIdsObj != null)
{ {
localCount++; // Has ProviderIds = external track
isExternal = true;
}
if (isExternal)
{
externalCount++;
} }
else else
{ {
externalCount++; localCount++;
} }
} }

View File

@@ -302,12 +302,32 @@ public class SpotifyTrackMatchingService : BackgroundService
// Check cache - use snapshot/timestamp to detect changes // Check cache - use snapshot/timestamp to detect changes
var existingMatched = await _cache.GetAsync<List<MatchedTrack>>(matchedTracksKey); var existingMatched = await _cache.GetAsync<List<MatchedTrack>>(matchedTracksKey);
if (existingMatched != null && existingMatched.Count >= tracksToMatch.Count)
// Check if we have manual mappings that need to be preserved
var hasManualMappings = false;
foreach (var track in tracksToMatch)
{
var manualMappingKey = $"spotify:manual-map:{playlistName}:{track.SpotifyId}";
var manualMapping = await _cache.GetAsync<string>(manualMappingKey);
if (!string.IsNullOrEmpty(manualMapping))
{
hasManualMappings = true;
break;
}
}
// Skip if cache exists AND no manual mappings need to be applied
if (existingMatched != null && existingMatched.Count >= tracksToMatch.Count && !hasManualMappings)
{ {
_logger.LogInformation("Playlist {Playlist} already has {Count} matched tracks cached, skipping", _logger.LogInformation("Playlist {Playlist} already has {Count} matched tracks cached, skipping",
playlistName, existingMatched.Count); playlistName, existingMatched.Count);
return; return;
} }
if (hasManualMappings)
{
_logger.LogInformation("Manual mappings detected for {Playlist}, rebuilding cache to apply them", playlistName);
}
var matchedTracks = new List<MatchedTrack>(); var matchedTracks = new List<MatchedTrack>();
var isrcMatches = 0; var isrcMatches = 0;