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:
schroda
2025-01-12 20:47:16 +01:00
parent 7ed345cf87
commit e25aa98365

View File

@@ -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,
},
};
},
);
},
},
);