From 12e89392671d151f80e365981b5f8b53af8589ca Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sat, 7 Dec 2024 23:19:01 +0100 Subject: [PATCH] Prevent duplicated downloads in download queue The mutation to add chapters to the download queue returns the current download queue. Thus, the local queue already includes the new downloads and adding them blindly in the download subscription will cause them to be in the local queue twice. --- src/lib/requests/RequestManager.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/requests/RequestManager.ts b/src/lib/requests/RequestManager.ts index 26c0c472..fa9695a9 100644 --- a/src/lib/requests/RequestManager.ts +++ b/src/lib/requests/RequestManager.ts @@ -2981,7 +2981,16 @@ export class RequestManager { return data; } - const queueWithAddedDownloads = [...data.downloadStatus.queue, ...downloadsToAdd]; + const downloadsToAddWithoutAlreadyKnown = downloadsToAdd.filter((download) => + data.downloadStatus.queue.every( + (queueDownload) => queueDownload.chapter.id !== download.chapter.id, + ), + ); + + const queueWithAddedDownloads = [ + ...data.downloadStatus.queue, + ...downloadsToAddWithoutAlreadyKnown, + ]; const queueWithoutRemovedDownloads = !downloadsToRemove.length ? queueWithAddedDownloads : queueWithAddedDownloads.filter(