mirror of
https://github.com/SoPat712/allstarr.git
synced 2026-02-09 23:55:10 -05:00
Fix manual mappings: preserve on rematch + fix local/external count detection
This commit is contained in:
@@ -262,14 +262,21 @@ public class AdminController : ControllerBase
|
||||
|
||||
foreach (var item in cachedPlaylistItems)
|
||||
{
|
||||
// Check if it's a local track (has Path) or external (no Path)
|
||||
if (item.TryGetValue("Path", out var pathObj) && pathObj != null)
|
||||
// Check if it's external by looking for ProviderIds (external songs have this)
|
||||
var isExternal = false;
|
||||
if (item.TryGetValue("ProviderIds", out var providerIdsObj) && providerIdsObj != null)
|
||||
{
|
||||
localCount++;
|
||||
// Has ProviderIds = external track
|
||||
isExternal = true;
|
||||
}
|
||||
|
||||
if (isExternal)
|
||||
{
|
||||
externalCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
externalCount++;
|
||||
localCount++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -302,12 +302,32 @@ public class SpotifyTrackMatchingService : BackgroundService
|
||||
|
||||
// Check cache - use snapshot/timestamp to detect changes
|
||||
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",
|
||||
playlistName, existingMatched.Count);
|
||||
return;
|
||||
}
|
||||
|
||||
if (hasManualMappings)
|
||||
{
|
||||
_logger.LogInformation("Manual mappings detected for {Playlist}, rebuilding cache to apply them", playlistName);
|
||||
}
|
||||
|
||||
var matchedTracks = new List<MatchedTrack>();
|
||||
var isrcMatches = 0;
|
||||
|
||||
Reference in New Issue
Block a user