Do not update "download status" on "download updates"
For large download queues this makes the app unusable. At the moment this is not needed anyway and once it is, it needs to be improved and only be done in the "download queue" page since the queue is only use there
This commit is contained in:
@@ -2954,74 +2954,6 @@ export class RequestManager {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const downloadsToRemove =
|
|
||||||
downloadChanged?.updates
|
|
||||||
.filter((update) =>
|
|
||||||
[
|
|
||||||
DownloadUpdateType.Dequeued,
|
|
||||||
DownloadUpdateType.Finished,
|
|
||||||
DownloadUpdateType.Position,
|
|
||||||
].includes(update.type),
|
|
||||||
)
|
|
||||||
.map((update) => update.download.chapter.id) ?? [];
|
|
||||||
const downloadsToAdd =
|
|
||||||
downloadChanged?.updates
|
|
||||||
.filter((update) => update.type === DownloadUpdateType.Queued)
|
|
||||||
.map((update) => update.download) ?? [];
|
|
||||||
const downloadsToReorder =
|
|
||||||
downloadChanged?.updates
|
|
||||||
.filter((update) => update.type === DownloadUpdateType.Position)
|
|
||||||
.map((update) => update.download) ?? [];
|
|
||||||
|
|
||||||
cache.updateQuery<GetDownloadStatusQuery, GetDownloadStatusQueryVariables>(
|
|
||||||
{
|
|
||||||
query: GET_DOWNLOAD_STATUS,
|
|
||||||
variables: {},
|
|
||||||
},
|
|
||||||
(data) => {
|
|
||||||
if (!data) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
|
||||||
(download) => !downloadsToRemove.includes(download.chapter.id),
|
|
||||||
);
|
|
||||||
|
|
||||||
const queueWithReorderedDownloads = !downloadsToReorder.length
|
|
||||||
? queueWithoutRemovedDownloads
|
|
||||||
: (() => {
|
|
||||||
const tmpQueue = [...queueWithoutRemovedDownloads];
|
|
||||||
|
|
||||||
downloadsToReorder.forEach((download) => {
|
|
||||||
tmpQueue.splice(download.position, 0, download);
|
|
||||||
});
|
|
||||||
|
|
||||||
return tmpQueue;
|
|
||||||
})();
|
|
||||||
|
|
||||||
return {
|
|
||||||
...data,
|
|
||||||
downloadStatus: {
|
|
||||||
...data.downloadStatus,
|
|
||||||
state: downloadChanged?.state ?? data.downloadStatus.state,
|
|
||||||
queue: queueWithReorderedDownloads,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user