Changed code to avoid duplicates making their way into the TrackedDownload cache.

This commit is contained in:
Taloth Saldono 2014-06-07 22:18:45 +02:00
parent b72c9b338c
commit 231128e01c
1 changed files with 6 additions and 4 deletions

View File

@ -105,7 +105,7 @@ namespace NzbDrone.Core.Download
var downloadClients = _downloadClientProvider.GetDownloadClients();
var oldTrackedDownloads = GetTrackedDownloads().ToDictionary(v => v.TrackingId);
var newTrackedDownloads = new List<TrackedDownload>();
var newTrackedDownloads = new Dictionary<String, TrackedDownload>();
var stateChanged = false;
@ -117,6 +117,8 @@ namespace NzbDrone.Core.Download
var trackingId = String.Format("{0}-{1}", downloadClient.Definition.Id, downloadItem.DownloadClientId);
TrackedDownload trackedDownload;
if (newTrackedDownloads.ContainsKey(trackingId)) continue;
if (!oldTrackedDownloads.TryGetValue(trackingId, out trackedDownload))
{
trackedDownload = new TrackedDownload
@ -133,11 +135,11 @@ namespace NzbDrone.Core.Download
trackedDownload.DownloadItem = downloadItem;
newTrackedDownloads.Add(trackedDownload);
newTrackedDownloads[trackingId] = trackedDownload;
}
}
foreach (var downloadItem in oldTrackedDownloads.Values.Except(newTrackedDownloads))
foreach (var downloadItem in oldTrackedDownloads.Values.Where(v => !newTrackedDownloads.ContainsKey(v.TrackingId)))
{
if (downloadItem.State != TrackedDownloadState.Removed)
{
@ -150,7 +152,7 @@ namespace NzbDrone.Core.Download
_logger.Trace("Stopped tracking download: {0}: {1}", downloadItem.TrackingId, downloadItem.DownloadItem.Title);
}
_trackedDownloadCache.Set("tracked", newTrackedDownloads.ToArray());
_trackedDownloadCache.Set("tracked", newTrackedDownloads.Values.ToArray());
return stateChanged;
}