mirror of
https://github.com/Radarr/Radarr
synced 2025-01-03 13:54:29 +00:00
Fixed: Don't try to remove the same item from queue multiple times
Closes #7932 (cherry picked from commit 2491da067815e129df3a3a79c0cc7221a9d87094)
This commit is contained in:
parent
7142d1f224
commit
364d8bd7c5
1 changed files with 44 additions and 26 deletions
|
@ -66,29 +66,62 @@ protected override QueueResource GetResourceById(int id)
|
|||
[RestDeleteById]
|
||||
public void RemoveAction(int id, bool removeFromClient = true, bool blocklist = false)
|
||||
{
|
||||
var trackedDownload = Remove(id, removeFromClient, blocklist);
|
||||
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);
|
||||
_trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
|
||||
[HttpDelete("bulk")]
|
||||
public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool removeFromClient = true, [FromQuery] bool blocklist = false)
|
||||
{
|
||||
var trackedDownloadIds = new List<string>();
|
||||
var pendingToRemove = new List<NzbDrone.Core.Queue.Queue>();
|
||||
var trackedToRemove = new List<TrackedDownload>();
|
||||
|
||||
foreach (var id in resource.Ids)
|
||||
{
|
||||
var trackedDownload = Remove(id, removeFromClient, blocklist);
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease != null)
|
||||
{
|
||||
pendingToRemove.Add(pendingRelease);
|
||||
continue;
|
||||
}
|
||||
|
||||
var trackedDownload = GetTrackedDownload(id);
|
||||
|
||||
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);
|
||||
trackedDownloadIds.Add(trackedDownload.DownloadItem.DownloadId);
|
||||
}
|
||||
|
||||
_trackedDownloadService.StopTracking(trackedDownloadIds);
|
||||
|
||||
return new { };
|
||||
|
@ -198,29 +231,14 @@ public PagingResource<QueueResource> GetQueue(bool includeUnknownMovieItems = fa
|
|||
}
|
||||
}
|
||||
|
||||
private TrackedDownload Remove(int id, bool removeFromClient, bool blocklist)
|
||||
private void Remove(NzbDrone.Core.Queue.Queue pendingRelease)
|
||||
{
|
||||
var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id);
|
||||
|
||||
if (pendingRelease != null)
|
||||
{
|
||||
if (blocklist)
|
||||
{
|
||||
_blocklistService.Block(pendingRelease.RemoteMovie, "Pending release manually blocklisted");
|
||||
}
|
||||
|
||||
_pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var trackedDownload = GetTrackedDownload(id);
|
||||
|
||||
if (trackedDownload == null)
|
||||
{
|
||||
throw new NotFoundException();
|
||||
}
|
||||
_blocklistService.Block(pendingRelease.RemoteMovie, "Pending release manually blocklisted");
|
||||
_pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id);
|
||||
}
|
||||
|
||||
private TrackedDownload Remove(TrackedDownload trackedDownload, bool removeFromClient, bool blocklist)
|
||||
{
|
||||
if (removeFromClient)
|
||||
{
|
||||
var downloadClient = _downloadClientProvider.Get(trackedDownload.DownloadClient);
|
||||
|
|
Loading…
Reference in a new issue