Skip to content

Commit

Permalink
Fixed: Ensure first history item when marked as failed is the selecte…
Browse files Browse the repository at this point in the history
…d item

(cherry picked from commit cf48bf304122bacc597de1d4d4429065d2358fa8)

Closes #3557
  • Loading branch information
markus101 authored and mynameisbogdan committed Feb 3, 2024
1 parent cf33d43 commit 1775dc9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/NzbDrone.Core/Download/FailedDownloadService.cs
Expand Up @@ -40,12 +40,23 @@ public void MarkAsFailed(int historyId, bool skipRedownload = false)
if (downloadId.IsNullOrWhiteSpace())
{
PublishDownloadFailedEvent(new List<EntityHistory> { history }, "Manually marked as failed", skipRedownload: skipRedownload);

return;
}
else

var grabbedHistory = new List<EntityHistory>();

// If the history item is a grabbed item (it should be, at least from the UI) add it as the first history item
if (history.EventType == EntityHistoryEventType.Grabbed)
{
var grabbedHistory = _historyService.Find(downloadId, EntityHistoryEventType.Grabbed).ToList();
PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed");
grabbedHistory.Add(history);
}

// Add any other history items for the download ID then filter out any duplicate history items.
grabbedHistory.AddRange(_historyService.Find(downloadId, EntityHistoryEventType.Grabbed));
grabbedHistory = grabbedHistory.DistinctBy(h => h.Id).ToList();

PublishDownloadFailedEvent(grabbedHistory, "Manually marked as failed");
}

public void MarkAsFailed(string downloadId, bool skipRedownload = false)
Expand All @@ -56,7 +67,7 @@ public void MarkAsFailed(string downloadId, bool skipRedownload = false)
{
var trackedDownload = _trackedDownloadService.Find(downloadId);

PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipRedownload);
PublishDownloadFailedEvent(history, "Manually marked as failed", trackedDownload, skipRedownload: skipRedownload);
}
}

Expand Down Expand Up @@ -124,7 +135,7 @@ private void PublishDownloadFailedEvent(List<EntityHistory> historyItems, string
var downloadFailedEvent = new DownloadFailedEvent
{
ArtistId = historyItem.ArtistId,
AlbumIds = historyItems.Select(h => h.AlbumId).ToList(),
AlbumIds = historyItems.Select(h => h.AlbumId).Distinct().ToList(),
Quality = historyItem.Quality,
SourceTitle = historyItem.SourceTitle,
DownloadClient = historyItem.Data.GetValueOrDefault(EntityHistory.DOWNLOAD_CLIENT),
Expand Down

0 comments on commit 1775dc9

Please sign in to comment.