Fixed: Don't try to remove the same item from queue multiple times

(cherry picked from commit 2491da067815e129df3a3a79c0cc7221a9d87094)

Closes #2087
pull/3261/head
Mark McDowall 2 years ago committed by Bogdan
parent 333d344c0b
commit bd265e47fa

@ -71,27 +71,60 @@ namespace Readarr.Api.V1.Queue
[RestDeleteById] [RestDeleteById]
public void RemoveAction(int id, bool removeFromClient = true, bool blocklist = false, bool skipRedownload = false) public void RemoveAction(int id, bool removeFromClient = true, bool blocklist = false, bool skipRedownload = false)
{ {
var trackedDownload = Remove(id, removeFromClient, blocklist, skipRedownload); var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
if (trackedDownload != null) if (pendingRelease != null)
{ {
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId); Remove(pendingRelease);
return;
} }
var trackedDownload = GetTrackedDownload(id);
if (trackedDownload == null)
{
throw new NotFoundException();
}
Remove(trackedDownload, removeFromClient, blocklist, skipRedownload);
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId);
} }
[HttpDelete("bulk")] [HttpDelete("bulk")]
public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool removeFromClient = true, [FromQuery] bool blocklist = false, [FromQuery] bool skipRedownload = false) public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool removeFromClient = true, [FromQuery] bool blocklist = false, [FromQuery] bool skipRedownload = false)
{ {
var trackedDownloadIds = new List<string>(); var trackedDownloadIds = new List<string>();
var pendingToRemove = new List<NzbDrone.Core.Queue.Queue>();
var trackedToRemove = new List<TrackedDownload>();
foreach (var id in resource.Ids) foreach (var id in resource.Ids)
{ {
var trackedDownload = Remove(id, removeFromClient, blocklist, skipRedownload); var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
if (pendingRelease != null)
{
pendingToRemove.Add(pendingRelease);
continue;
}
var trackedDownload = GetTrackedDownload(id);
if (trackedDownload != null) if (trackedDownload != null)
{ {
trackedDownloadIds.Add(trackedDownload.DownloadItem.DownloadId); trackedToRemove.Add(trackedDownload);
}
}
foreach (var pendingRelease in pendingToRemove.DistinctBy(p => p.Id))
{
Remove(pendingRelease);
} }
foreach (var trackedDownload in trackedToRemove.DistinctBy(t => t.DownloadItem.DownloadId))
{
Remove(trackedDownload, removeFromClient, blocklist, skipRedownload);
trackedDownloadIds.Add(trackedDownload.DownloadItem.DownloadId);
} }
_trackedDownloadService.StopTracking(trackedDownloadIds); _trackedDownloadService.StopTracking(trackedDownloadIds);
@ -206,25 +239,14 @@ namespace Readarr.Api.V1.Queue
} }
} }
private TrackedDownload Remove(int id, bool removeFromClient, bool blocklist, bool skipRedownload) private void Remove(NzbDrone.Core.Queue.Queue pendingRelease)
{
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
if (pendingRelease != null)
{ {
_blocklistService.Block(pendingRelease.RemoteBook, "Pending book manually blocklisted"); _blocklistService.Block(pendingRelease.RemoteBook, "Pending release manually blocklisted");
_pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id); _pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id);
return null;
} }
var trackedDownload = GetTrackedDownload(id); private TrackedDownload Remove(TrackedDownload trackedDownload, bool removeFromClient, bool blocklist, bool skipRedownload)
if (trackedDownload == null)
{ {
throw new NotFoundException();
}
if (removeFromClient) if (removeFromClient)
{ {
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient); var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);

Loading…
Cancel
Save